home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 5 / MacMania 5.toast / / Internet software / NewsWatcher / NW Source / Shared Code / Libraries & Misc / OpenTransport.h < prev    next >
Text File  |  1996-10-01  |  80KB  |  2,345 lines

  1. /*
  2.     File:        OpenTransport.h
  3.  
  4.     Contains:    Open Transport client interface file.  This contains all the client APIs
  5.                 that are available to 68K clients on PowerPC machines running System 7.
  6.  
  7.     Copyright:    © 1993-1996 by Apple Computer, Inc. and Mentat Inc., all rights reserved.
  8.  
  9.  
  10. */
  11.  
  12. #ifndef __OPENTRANSPORT__
  13. #define __OPENTRANSPORT__
  14.  
  15. #ifndef SystemSevenOrLater
  16. #define SystemSevenOrLater    1
  17. #endif
  18.  
  19. #ifndef __TYPES__
  20. #include <Types.h>
  21. #endif
  22. #ifndef __STDDEF__
  23. #include <stddef.h>
  24. #endif
  25.  
  26. #if GENERATING68K && defined(__MWERKS__)
  27. #pragma pointers_in_D0
  28. #endif
  29.  
  30. /*    -------------------------------------------------------------------------
  31.     Define what functions look like
  32.     ------------------------------------------------------------------------- */
  33.     
  34. #define _CDECL
  35. #define _MDECL
  36.  
  37. #if defined(__SC__) || defined(THINK_CPLUS) || defined(__MRC__)
  38.     #ifdef __cplusplus
  39.         #undef _CDECL
  40.         #undef _MDECL
  41.         #define _CDECL            _cdecl
  42.         #define _MDECL            _cdecl
  43.     #endif
  44. #endif
  45.  
  46. #if GENERATING68K
  47.     typedef unsigned long    uchar_p;
  48.     typedef unsigned long    ushort_p;
  49.     typedef long            short_p;
  50.     typedef long            char_p;
  51.     typedef long            boolean_p;
  52.     typedef long            int_t;
  53.     typedef unsigned long    uint_t;
  54. #else
  55.     typedef unsigned char    uchar_p;
  56.     typedef unsigned short    ushort_p;
  57.     typedef short            short_p;
  58.     typedef char            char_p;
  59.     typedef Boolean            boolean_p;
  60.     typedef long            int_t;
  61.     typedef unsigned long    uint_t;
  62. #endif
  63.  
  64. #ifndef __MIXEDMODE__
  65. #include <MixedMode.h>
  66. #endif
  67.  
  68. #ifndef OTKERNEL
  69. #define OTKERNEL    0
  70. #endif
  71. #ifndef OTUNIXERRORS
  72. #define OTUNIXERRORS    0
  73. #endif
  74.  
  75. #if PRAGMA_ALIGN_SUPPORTED
  76. #pragma options align=mac68k
  77. #endif
  78. #if PRAGMA_IMPORT_SUPPORTED
  79. #pragma import on
  80. #endif
  81.  
  82. #ifdef __cplusplus
  83. extern "C" {
  84. #endif
  85.  
  86. /*******************************************************************************
  87. ** Some prefixes for shared libraries
  88. ********************************************************************************/
  89.  
  90. #define kOTLibraryVersion        "1.1"
  91.  
  92. #define kOTLibraryPrefix         "OTLib$"
  93. #define kOTModulePrefix            "OTModl$"
  94. #define kOTClientPrefix            "OTClnt$"
  95. #define kOTKernelPrefix            "OTKrnl$"
  96.  
  97. /*******************************************************************************
  98. ** Gestalt values for Open Transport
  99. ********************************************************************************/
  100.  
  101. enum
  102. {
  103.     gestaltOpenTptVersions            = 'otvr',
  104.     gestaltOpenTpt                    = 'otan',
  105.     
  106.     gestaltOpenTptPresentMask            = 0x00000001,
  107.     gestaltOpenTptLoadedMask            = 0x00000002,
  108.     gestaltOpenTptAppleTalkPresentMask    = 0x00000004,
  109.     gestaltOpenTptAppleTalkLoadedMask    = 0x00000008,
  110.     gestaltOpenTptTCPPresentMask        = 0x00000010,
  111.     gestaltOpenTptTCPLoadedMask            = 0x00000020,
  112.     gestaltOpenTptIPXSPXPresentMask        = 0x00000040,
  113.     gestaltOpenTptIPXSPXLoadedMask        = 0x00000080,
  114.     
  115.     gestaltOpenTptPresentBit            = 0,
  116.     gestaltOpenTptLoadedBit                = 1,
  117.     gestaltOpenTptAppleTalkPresentBit    = 2,
  118.     gestaltOpenTptAppleTalkLoadedBit    = 3,
  119.     gestaltOpenTptTCPPresentBit            = 4,
  120.     gestaltOpenTptTCPLoadedBit            = 5,
  121.     gestaltOpenTptIPXSPXPresentBit        = 6,
  122.     gestaltOpenTptIPXSPXLoadedBit        = 7
  123. };
  124.  
  125. /*******************************************************************************
  126. ** Some typedefs used by the OpenTransport system
  127. ********************************************************************************/
  128.  
  129. /*    -------------------------------------------------------------------------
  130.     Miscellaneous typedefs
  131.     ------------------------------------------------------------------------- */
  132.  
  133. typedef UInt32                OTTimeout;        /* A millisecond timeout value                    */
  134. typedef long                OTSequence;        /* An ID number in connections/transactions        */
  135. typedef long                OTNameID;        /* An ID number for registered names            */
  136. typedef SInt32                OTReason;        /* A protocol-specific reason code for failure    */
  137.                                             /* Usually a Unix-style positive error code        */
  138. typedef UInt32                OTQLen;            /* # outstanding connection requests at 1 time    */
  139. typedef void*                OTClient;        /* value describing a client                    */
  140. typedef UInt8*                OTClientName;    /* Will become internationalizeable shortly        */
  141. typedef long                OTCommand;        /* The command code in STREAMS messages            */
  142.  
  143. /*    -------------------------------------------------------------------------
  144.     OTOpenFlags - flags used for opening providers
  145.     ------------------------------------------------------------------------- */
  146.  
  147. typedef UInt32                OTOpenFlags;
  148.  
  149. enum
  150. {
  151.     O_ASYNC        = 0x01,
  152.     O_NDELAY    = 0x04,
  153.     O_NONBLOCK    = 0x04
  154. };
  155.  
  156. /*    -------------------------------------------------------------------------
  157.     StdCLib-style Error codes
  158.     ------------------------------------------------------------------------- */
  159.  
  160. typedef UInt16                    OTUnixErr;
  161.  
  162. #if OTKERNEL || OTUNIXERRORS
  163.  
  164.     /*
  165.      * There may be some error code confusions with other compiler vendor header
  166.      * files - However, these match both MPW and AIX definitions.
  167.      * We undefine the #defined ones we know about so that we can put them
  168.      * in an enum.
  169.      */
  170.      
  171.     #undef EPERM
  172.     #undef ENOENT
  173.     #undef ENORSRC
  174.     #undef EINTR
  175.     #undef EIO
  176.     #undef ENXIO
  177.     #undef E2BIG
  178.     #undef EBADF
  179.     #undef EAGAIN
  180.     #undef ENOMEM
  181.     #undef EACCES
  182.     #undef EFAULT
  183.     #undef EBUSY
  184.     #undef EEXIST
  185.     #undef ENODEV
  186.     #undef EINVAL
  187.     #undef ENOTTY
  188.     #undef ERANGE
  189.     #undef ESRCH
  190.     #undef EPIPE
  191.  
  192.     enum
  193.     {
  194.         EPERM            = 1,        /* Permission denied                    */
  195.         ENOENT            = 2,        /* No such file or directory            */
  196.         ENORSRC          = 3,        /* No such resource                        */
  197.         EINTR            = 4,        /* Interrupted system service            */
  198.         EIO             = 5,        /* I/O error                            */
  199.         ENXIO            = 6,        /* No such device or address            */
  200.         EBADF             = 9,        /* Bad file number                        */
  201.         EAGAIN            = 11,        /* Try operation again later            */
  202.         ENOMEM            = 12,        /* Not enough space                        */
  203.         EACCES            = 13,        /* Permission denied                    */
  204.         EFAULT            = 14,        /* Bad address                            */
  205.         EBUSY            = 16,        /* Device or resource busy                */
  206.         EEXIST            = 17,        /* File exists                            */
  207.         ENODEV            = 19,        /* No such device                        */
  208.         EINVAL            = 22,        /* Invalid argument                        */
  209.         ENOTTY            = 25,        /* Not a character device                */
  210.         EPIPE            = 32,        /* Broken pipe                            */
  211.         ERANGE            = 34,        /* Math result not representable        */
  212.         EDEADLK            = 35,        /* Call would block so was aborted        */ 
  213.         EWOULDBLOCK        = EDEADLK,    /* Or a deadlock would occur            */
  214.         EALREADY        = 37,
  215.         ENOTSOCK        = 38,        /* Socket operation on non-socket        */
  216.         EDESTADDRREQ    = 39,        /* Destination address required            */
  217.         EMSGSIZE        = 40,        /* Message too long                        */
  218.         EPROTOTYPE        = 41,        /* Protocol wrong type for socket        */
  219.         ENOPROTOOPT        = 42,        /* Protocol not available                */
  220.         EPROTONOSUPPORT    = 43,        /* Protocol not supported                */
  221.         ESOCKTNOSUPPORT    = 44,        /* Socket type not supported            */
  222.         EOPNOTSUPP        = 45,        /* Operation not supported on socket    */
  223.         EADDRINUSE        = 48,        /* Address already in use                */
  224.         EADDRNOTAVAIL    = 49,        /* Can't assign requested address        */
  225.     
  226.         ENETDOWN        = 50,        /* Network is down                        */
  227.         ENETUNREACH        = 51,        /* Network is unreachable                */
  228.         ENETRESET        = 52,        /* Network dropped connection on reset    */
  229.         ECONNABORTED    = 53,        /* Software caused connection abort        */
  230.         ECONNRESET        = 54,        /* Connection reset by peer                */
  231.         ENOBUFS            = 55,        /* No buffer space available            */
  232.         EISCONN            = 56,        /* Socket is already connected            */
  233.         ENOTCONN        = 57,        /* Socket is not connected                */
  234.         ESHUTDOWN        = 58,        /* Can't send after socket shutdown        */
  235.         ETOOMANYREFS    = 59,        /* Too many references: can't splice    */
  236.         ETIMEDOUT        = 60,        /* Connection timed out                    */
  237.         ECONNREFUSED    = 61,        /* Connection refused                    */
  238.     
  239.         EHOSTDOWN        = 64,        /* Host is down                            */
  240.         EHOSTUNREACH    = 65,        /* No route to host                        */
  241.     
  242.         EPROTO            = 70,
  243.         ETIME            = 71,
  244.         ENOSR            = 72,
  245.         EBADMSG            = 73,
  246.         ECANCEL            = 74,
  247.         ENOSTR            = 75,
  248.         ENODATA            = 76,
  249.         EINPROGRESS        = 77,
  250.     
  251.         ESRCH             = 78,
  252.         ENOMSG            = 79,
  253.     
  254.         ELASTERRNO        = 79
  255.     };
  256.  
  257. #endif
  258.  
  259. /*    -------------------------------------------------------------------------
  260.     Open Transport/XTI Error codes
  261.     ------------------------------------------------------------------------- */
  262.  
  263. typedef UInt16                    OTXTIErr;
  264.  
  265.     enum
  266.     {
  267.         TSUCCESS        = 0,    /* No Error occurred                        */
  268.         TBADADDR        = 1,    /* A Bad address was specified                */
  269.         TBADOPT         = 2,    /* A Bad option was specified                */
  270.         TACCES            = 3,    /* Missing access permission                */
  271.         TBADF            = 4,    /* Bad provider reference                    */
  272.         TNOADDR         = 5,    /* No address was specified                    */
  273.         TOUTSTATE        = 6,    /* Call issued in wrong state                */
  274.         TBADSEQ         = 7,    /* Sequence specified does not exist        */
  275.         TSYSERR         = 8,    /* A system error occurred                    */
  276.         TLOOK            = 9,    /* An event occurred - call Look()            */
  277.         TBADDATA        = 10,    /* An illegal amount of data was specified    */
  278.         TBUFOVFLW        = 11,    /* Passed buffer not big enough                */
  279.         TFLOW            = 12,    /* Provider is flow-controlled                */
  280.         TNODATA         = 13,    /* No data available for reading            */
  281.         TNODIS            = 14,    /* No disconnect indication available        */
  282.         TNOUDERR        = 15,    /* No Unit Data Error indication available    */
  283.         TBADFLAG        = 16,    /* A Bad flag value was supplied            */
  284.         TNOREL            = 17,    /* No orderly release indication available    */
  285.         TNOTSUPPORT     = 18,    /* Command is not supported                    */
  286.         TSTATECHNG        = 19,    /* State is changing - try again later        */
  287.         TNOSTRUCTYPE    = 20,    /* Bad structure type requested for OTAlloc    */
  288.         TBADNAME        = 21,    /* A bad endpoint name was supplied            */
  289.         TBADQLEN        = 22,    /* A Bind to an in-use address with qlen > 0*/
  290.         TADDRBUSY        = 23,    /* Address requested is already in use        */
  291.         TINDOUT         = 24,    /* Accept failed because of pending listen    */
  292.         TPROVMISMATCH    = 25,    /* Tried to accept on incompatible endpoint    */
  293.         TRESQLEN        = 26,
  294.         TRESADDR        = 27,
  295.         TQFULL            = 28,
  296.         TPROTO            = 29,    /* An unspecified provider error occurred    */
  297.         TBADSYNC        = 30,    /* A synchronous call at interrupt time        */
  298.         TCANCELED        = 31,    /* The command was cancelled                */
  299.         
  300.         TLASTXTIERROR    = 31
  301.     };
  302.  
  303. /*    -------------------------------------------------------------------------
  304.     Standard negative error codes conforming to both the Open Transport/XTI
  305.     errors and the Exxxxx StdCLib errors.
  306.     These are returned as OSStatus' from functions, and to the OTResult parameter
  307.     of a notification function or method.  However, OTResult may sometimes
  308.     contain other values depending on the notification.
  309.     ------------------------------------------------------------------------- */
  310.  
  311. typedef SInt32                OTResult;
  312.     /*
  313.      * These map the Open Transport/XTI errors (the Txxxx error codes), and the
  314.      * StdCLib Exxxx error codes into unique spaces in the Apple OSStatus space.
  315.      */
  316.     #define XTI2OSStatus(x)            (-3149 - (x))
  317.     #define E2OSStatus(x)            (-3199 - (x))
  318.  
  319.     #define OSStatus2XTI(x)            ((OTXTIErr)(-3149 - (x)))
  320.     #define OSStatus2E(x)            ((OTUnixErr)(-3199 - (x)))
  321.     
  322.     #define IsXTIError(x)            ((x) < -3149 && (x) >= (-3149 - TLASTXTIERROR))
  323.     #define IsEError(x)                ((x) < -3199 && (x) >= (-3199 - ELASTERRNO))
  324.  
  325.     enum
  326.     {
  327.         kOTNoError                = (OSStatus)0,        /* No Error occurred                            */
  328.         kOTOutOfMemoryErr        = -3211,
  329.         kOTNotFoundErr            = -3201,
  330.         kOTDuplicateFoundErr    = -3216,
  331.         /*
  332.          * Remapped XTI error codes
  333.          */
  334.         kOTBadAddressErr        = XTI2OSStatus(TBADADDR),        /* -3150 A Bad address was specified                */
  335.         kOTBadOptionErr            = XTI2OSStatus(TBADOPT),        /* -3151 A Bad option was specified                    */
  336.         kOTAccessErr            = XTI2OSStatus(TACCES),            /* -3152 Missing access permission                    */
  337.         kOTBadReferenceErr        = XTI2OSStatus(TBADF),            /* -3153 Bad provider reference                        */
  338.         kOTNoAddressErr            = XTI2OSStatus(TNOADDR),        /* -3154 No address was specified                    */
  339.         kOTOutStateErr            = XTI2OSStatus(TOUTSTATE),        /* -3155 Call issued in wrong state                    */
  340.         kOTBadSequenceErr        = XTI2OSStatus(TBADSEQ),        /* -3156 Sequence specified does not exist            */
  341.         kOTSysErrorErr            = XTI2OSStatus(TSYSERR),        /* -3157 A system error occurred                    */
  342.         kOTLookErr                = XTI2OSStatus(TLOOK),            /* -3158 An event occurred - call Look()            */
  343.         kOTBadDataErr            = XTI2OSStatus(TBADDATA),        /* -3159 An illegal amount of data was specified    */
  344.         kOTBufferOverflowErr    = XTI2OSStatus(TBUFOVFLW),        /* -3160 Passed buffer not big enough                */
  345.         kOTFlowErr                = XTI2OSStatus(TFLOW),            /* -3161 Provider is flow-controlled                */
  346.         kOTNoDataErr            = XTI2OSStatus(TNODATA),        /* -3162 No data available for reading                */
  347.         kOTNoDisconnectErr        = XTI2OSStatus(TNODIS),            /* -3163 No disconnect indication available            */
  348.         kOTNoUDErrErr            = XTI2OSStatus(TNOUDERR),        /* -3164 No Unit Data Error indication available    */
  349.         kOTBadFlagErr            = XTI2OSStatus(TBADFLAG),        /* -3165 A Bad flag value was supplied                */
  350.         kOTNoReleaseErr            = XTI2OSStatus(TNOREL),            /* -3166 No orderly release indication available    */
  351.         kOTNotSupportedErr        = XTI2OSStatus(TNOTSUPPORT),    /* -3167 Command is not supported                    */
  352.         kOTStateChangeErr        = XTI2OSStatus(TSTATECHNG),        /* -3168 State is changing - try again later        */
  353.         kOTNoStructureTypeErr    = XTI2OSStatus(TNOSTRUCTYPE),    /* -3169 Bad structure type requested for OTAlloc    */
  354.         kOTBadNameErr            = XTI2OSStatus(TBADNAME),        /* -3170 A bad endpoint name was supplied            */
  355.         kOTBadQLenErr            = XTI2OSStatus(TBADQLEN),        /* -3171 A Bind to an in-use addr with qlen > 0        */
  356.         kOTAddressBusyErr        = XTI2OSStatus(TADDRBUSY),        /* -3172 Address requested is already in use        */
  357.         kOTIndOutErr            = XTI2OSStatus(TINDOUT),        /* -3173 Accept failed because of pending listen    */
  358.         kOTProviderMismatchErr    = XTI2OSStatus(TPROVMISMATCH),    /* -3174 Tried to accept on incompatible endpoint    */
  359.         kOTResQLenErr            = XTI2OSStatus(TRESQLEN),        /* -3175                                            */
  360.         kOTResAddressErr        = XTI2OSStatus(TRESADDR),        /* -3176                                            */
  361.         kOTQFullErr                = XTI2OSStatus(TQFULL),            /* -3177                                            */
  362.         kOTProtocolErr            = XTI2OSStatus(TPROTO),            /* -3178 An unspecified provider error occurred        */
  363.         kOTBadSyncErr            = XTI2OSStatus(TBADSYNC),        /* -3179 A synchronous call at interrupt time        */
  364.         kOTCanceledErr            = XTI2OSStatus(TCANCELED),        /* -3180 The command was cancelled                    */
  365.         /*
  366.          * Remapped StdCLib error codes.
  367.          */
  368.         kEPERMErr                    = -3200,        /*  Permission denied                    */
  369.         kENOENTErr                    = -3201,        /*  No such file or directory            */
  370.         kENORSRCErr                    = -3202,        /*  No such resource                    */
  371.         kEINTRErr                    = -3203,        /*  Interrupted system service            */
  372.         kEIOErr                        = -3204,        /*  I/O error                            */
  373.         kENXIOErr                    = -3205,        /*  No such device or address            */
  374.         kEBADFErr                    = -3208,        /*  Bad file number                        */
  375.         kEAGAINErr                    = -3210,        /*  Try operation again later            */
  376.         kENOMEMErr                    = -3211,        /*  Not enough space                    */
  377.         kEACCESErr                    = -3212,        /*  Permission denied                    */
  378.         kEFAULTErr                    = -3213,        /*  Bad address                            */
  379.         kEBUSYErr                    = -3215,        /*  Device or resource busy                */
  380.         kEEXISTErr                    = -3216,        /*  File exists                            */
  381.         kENODEVErr                    = -3218,        /*  No such device                        */
  382.         kEINVALErr                    = -3221,        /*  Invalid argument                    */
  383.         kENOTTYErr                    = -3224,        /*  Not a character device                */
  384.         kEPIPEErr                    = -3231,        /*  Broken pipe                            */
  385.         kERANGEErr                    = -3233,        /*  Message size too large for STREAM    */
  386.         kEWOULDBLOCKErr                = -3234,        /*  Call would block, so was aborted    */
  387.         kEDEADLKErr                    = -3234,        /*  or a deadlock would occur            */
  388.         kEALREADYErr                = -3236,        /*                                         */
  389.         kENOTSOCKErr                = -3237,        /*  Socket operation on non-socket        */
  390.         kEDESTADDRREQErr            = -3238,        /*  Destination address required        */
  391.         kEMSGSIZEErr                = -3239,        /*  Message too long                    */
  392.         kEPROTOTYPEErr                = -3240,        /*  Protocol wrong type for socket        */
  393.         kENOPROTOOPTErr                = -3241,        /*  Protocol not available                */
  394.         kEPROTONOSUPPORTErr         = -3242,        /*  Protocol not supported                */
  395.         kESOCKTNOSUPPORTErr         = -3243,        /*  Socket type not supported            */
  396.         kEOPNOTSUPPErr                = -3244,        /*  Operation not supported on socket    */
  397.         kEADDRINUSEErr                = -3247,        /*  Address already in use                */
  398.         kEADDRNOTAVAILErr            = -3248,        /*  Can't assign requested address        */
  399.         kENETDOWNErr                = -3249,        /*  Network is down                        */
  400.         kENETUNREACHErr                = -3250,        /*  Network is unreachable                */
  401.         kENETRESETErr                = -3251,        /*  Network dropped connection on reset    */
  402.         kECONNABORTEDErr            = -3252,        /*  Software caused connection abort    */
  403.         kECONNRESETErr                = -3253,        /*  Connection reset by peer            */
  404.         kENOBUFSErr                    = -3254,        /*  No buffer space available            */
  405.         kEISCONNErr                    = -3255,        /*  Socket is already connected            */
  406.         kENOTCONNErr                = -3256,        /*  Socket is not connected                */
  407.         kESHUTDOWNErr                = -3257,        /*  Can't send after socket shutdown    */
  408.         kETOOMANYREFSErr            = -3258,        /*  Too many references: can't splice    */
  409.         kETIMEDOUTErr                = -3259,        /*  Connection timed out                */
  410.         kECONNREFUSEDErr            = -3260,        /*  Connection refused                    */
  411.         kEHOSTDOWNErr                = -3263,        /*  Host is down                        */
  412.         kEHOSTUNREACHErr            = -3264,        /*  No route to host                    */
  413.         kEPROTOErr                    = -3269,        /*                                         */
  414.         kETIMEErr                    = -3270,        /*                                         */
  415.         kENOSRErr                    = -3271,        /*                                         */
  416.         kEBADMSGErr                    = -3272,        /*                                         */
  417.         kECANCELErr                    = -3273,        /*                                         */
  418.         kENOSTRErr                    = -3274,        /*                                         */
  419.         kENODATAErr                    = -3275,        /*                                         */
  420.         kEINPROGRESSErr                = -3276,        /*                                         */
  421.         kESRCHErr                    = -3277,        /*                                         */
  422.         kENOMSGErr                    = -3278,        /*                                         */
  423.         
  424.         kOTClientNotInittedErr        = -3279,
  425.         kOTPortHasDiedErr            = -3280,
  426.         kOTPortWasEjectedErr        = -3281,
  427.         kOTBadConfigurationErr        = -3282,
  428.         kOTConfigurationChangedErr    = -3283,
  429.         kOTUserRequestedErr            = -3284,
  430.         kOTPortLostConnection        = -3285    
  431.     };
  432.     
  433. /*    -------------------------------------------------------------------------
  434.     OTAddressType - defines the address type for the OTAddress
  435.     ------------------------------------------------------------------------- */
  436.  
  437. typedef UInt16        OTAddressType;
  438.  
  439. enum
  440. {
  441.     kOTGenericName    = 0
  442. };
  443.  
  444. /*    -------------------------------------------------------------------------
  445.     OTAddress - Generic OpenTransport protocol address
  446.     ------------------------------------------------------------------------- */
  447.  
  448. struct OTAddress
  449. {
  450.     OTAddressType    fAddressType;
  451.     UInt8            fAddress[1];
  452. };
  453.  
  454. typedef struct OTAddress    OTAddress;
  455.  
  456. /*    -------------------------------------------------------------------------
  457.     OTStructType - defines the structure type for the OTAlloc call
  458.     ------------------------------------------------------------------------- */
  459.  
  460. typedef UInt32                OTStructType;
  461.  
  462.     enum
  463.     {
  464.         T_BIND            = (OTStructType)1,
  465.         T_OPTMGMT        = (OTStructType)2,
  466.         T_CALL            = (OTStructType)3,
  467.         T_DIS            = (OTStructType)4,
  468.         T_UNITDATA        = (OTStructType)5,
  469.         T_UDERROR        = (OTStructType)6,
  470.         T_INFO            = (OTStructType)7,
  471.         T_REPLYDATA        = (OTStructType)8,
  472.         T_REQUESTDATA    = (OTStructType)9,
  473.         T_UNITREQUEST    = (OTStructType)10,
  474.         T_UNITREPLY        = (OTStructType)11
  475.     };
  476.  
  477. /*    -------------------------------------------------------------------------
  478.     OTFlags - flags for sending and receiving data
  479.     ------------------------------------------------------------------------- */
  480.  
  481. typedef UInt32                OTFlags;
  482.  
  483.     enum
  484.     {
  485.         T_MORE            = 0x001,    /* More data to come in message        */
  486.         T_EXPEDITED     = 0x002,    /* Data is expedited, if possible    */
  487.         T_ACKNOWLEDGED    = 0x004,    /* Acknowledge transaction            */
  488.         T_PARTIALDATA    = 0x008,    /* Partial data - more coming        */
  489.         T_NORECEIPT        = 0x010,    /* No event on transaction done        */
  490.         T_TIMEDOUT        = 0x020        /* Reply timed out                    */
  491.     };
  492.  
  493. /*    -------------------------------------------------------------------------
  494.     OTBand - a band value when reading priority messages
  495.     ------------------------------------------------------------------------- */
  496.  
  497. typedef UInt32        OTBand;            /* A priority band value                    */
  498.  
  499. /*    -------------------------------------------------------------------------
  500.     Reference values
  501.     ------------------------------------------------------------------------- */
  502.  
  503. #ifdef __cplusplus
  504. typedef struct TProvider*    ProviderRef;
  505. typedef struct TEndpoint*    EndpointRef;
  506. typedef struct TMapper*        MapperRef;
  507. #else
  508. typedef void*                ProviderRef;
  509. typedef void*                EndpointRef;
  510. typedef void*                MapperRef;
  511. #endif
  512.  
  513. enum 
  514. {
  515.     kOTInvalidRef            = 0
  516. };
  517.  
  518. #define kOTInvalidProviderRef    ((ProviderRef)0)
  519. #define kOTInvalidEndpointRef    ((EndpointRef)0)
  520. #define kOTInvalidMapperRef        ((MapperRef)0)
  521.  
  522. /*    -------------------------------------------------------------------------
  523.     OTEventCode values for Open Transport - These are the event codes that
  524.     are sent to notification routine during asynchronous processing.
  525.     ------------------------------------------------------------------------- */
  526.  
  527. typedef UInt32    OTEventCode;
  528. /*
  529.  * Function definition to handle notification from providers
  530.  *
  531.  * This is never a UniversalProcPtr.
  532.  */
  533. typedef pascal void (*OTNotifyProcPtr)(void* contextPtr, OTEventCode code, 
  534.                                        OTResult result, void* cookie);
  535.  
  536. enum
  537. {
  538.     /*
  539.      * These will be returned by the T_LOOK function, or will be returned
  540.      * if asynchronous notification is used.
  541.      */
  542.     T_LISTEN                    = (OTEventCode)0x0001,        /* An connection request is available     */
  543.     T_CONNECT                    = (OTEventCode)0x0002,        /* Confirmation of a connect request    */ 
  544.     T_DATA                        = (OTEventCode)0x0004,        /* Standard data is available            */
  545.     T_EXDATA                    = (OTEventCode)0x0008,        /* Expedited data is available            */
  546.     T_DISCONNECT                = (OTEventCode)0x0010,        /* A disconnect is available            */
  547.     T_ERROR                     = (OTEventCode)0x0020,        /* obsolete/unused in library            */
  548.     T_UDERR                     = (OTEventCode)0x0040,        /* A Unit Data Error has occurred        */
  549.     T_ORDREL                    = (OTEventCode)0x0080,        /* An orderly release is available        */
  550.     T_GODATA                    = (OTEventCode)0x0100,        /* Flow control lifted on standard data    */
  551.     T_GOEXDATA                    = (OTEventCode)0x0200,        /* Flow control lifted on expedited data*/
  552.     T_REQUEST                    = (OTEventCode)0x0400,        /* An Incoming request is available        */
  553.     T_REPLY                        = (OTEventCode)0x0800,        /* An Incoming reply is available        */
  554.     T_PASSCON                     = (OTEventCode)0x1000,        /* State is now T_DATAXFER                */
  555.     T_RESET                     = (OTEventCode)0x2000,        /* Protocol has been reset                */
  556.  
  557.     /*
  558.      * kPRIVATEEVENT + 1 through kPRIVATEEVENT + 0xffff
  559.      *        may be used for any private event codes desired.
  560.      *        All other event codes are reserved for Apple Computer, Inc.
  561.      *        use only.
  562.      */
  563.     kPRIVATEEVENT                = (OTEventCode)0x10000000,
  564.     /*
  565.      * These are only returned if asynchronous notification is being used
  566.      */
  567.     kCOMPLETEEVENT                = (OTEventCode)0x20000000,
  568.     
  569.     T_BINDCOMPLETE                = (OTEventCode)0x20000001,    /* Bind call is complete                */    
  570.     T_UNBINDCOMPLETE            = (OTEventCode)0x20000002,    /* Unbind call is complete                */
  571.     T_ACCEPTCOMPLETE            = (OTEventCode)0x20000003,    /* Accept call is complete                */
  572.     T_REPLYCOMPLETE                = (OTEventCode)0x20000004,    /* SendReply call is complete            */
  573.     T_DISCONNECTCOMPLETE        = (OTEventCode)0x20000005,    /* Disconnect call is complete            */
  574.     T_OPTMGMTCOMPLETE            = (OTEventCode)0x20000006,    /* OptMgmt call is complete                */
  575.     T_OPENCOMPLETE                = (OTEventCode)0x20000007,    /* An Open call is complete                */
  576.     T_GETPROTADDRCOMPLETE        = (OTEventCode)0x20000008,    /* GetProtAddress call is complete        */
  577.     T_RESOLVEADDRCOMPLETE        = (OTEventCode)0x20000009,    /* A ResolveAddress call is complet        */
  578.     T_GETINFOCOMPLETE            = (OTEventCode)0x2000000A,    /* A GetInfo call is complete            */
  579.     T_SYNCCOMPLETE                = (OTEventCode)0x2000000B,    /* A Sync call is complete                */
  580.     T_MEMORYRELEASED            = (OTEventCode)0x2000000C,    /* No-copy memory was released            */
  581.     T_REGNAMECOMPLETE            = (OTEventCode)0x2000000D,    /* A RegisterName call is complete        */
  582.     T_DELNAMECOMPLETE            = (OTEventCode)0x2000000E,    /* A DeleteName call is complete        */
  583.     T_LKUPNAMECOMPLETE            = (OTEventCode)0x2000000F,    /* A LookupName call is complete        */
  584.     T_LKUPNAMERESULT            = (OTEventCode)0x20000010,    /* A LookupName is returning a name        */
  585.     kOTSyncIdleEvent            = (OTEventCode)0x20000011,    /* Synchronous call Idle event            */
  586.     /*
  587.      * These are events you get using the STREAMS functions like
  588.      * IOCtl, PutMessage, and GetMessage
  589.      */
  590.     kSTREAMEVENT                = (OTEventCode)0x21000000,
  591.  
  592.     kGetmsgEvent                = (OTEventCode)0x21000002,    /* A GetMessage call is complete        */
  593.     kStreamReadEvent            = (OTEventCode)0x21000003,    /* A Read call is complete                */
  594.     kStreamWriteEvent            = (OTEventCode)0x21000004,    /* A Write call is complete                */
  595.     kStreamIoctlEvent            = (OTEventCode)0x21000005,    /* An Ioctl call is complete            */
  596.     kStreamOpenEvent            = (OTEventCode)0x21000007,    /* An OpenStream call is complete        */
  597.     kPollEvent                    = (OTEventCode)0x21000008,    /* A Poll call is complete                */
  598.  
  599.     kSIGNALEVENT                = (OTEventCode)0x22000000,    /* A signal has arrived from the STREAM    */
  600.     
  601.     kPROTOCOLEVENT                = (OTEventCode)0x23000000,    /* Some event from the protocols        */
  602.     /*
  603.      * These are miscellaneous events that could be sent to a provider
  604.      */
  605.     kOTProviderIsDisconnected    = (OTEventCode)0x23000001,    /* Provider is temporarily off-line        */
  606.     kOTProviderIsReconnected    = (OTEventCode)0x23000002,    /* Provider is now back on-line            */
  607.     /*
  608.      * These are system events sent to each provider.
  609.      */
  610.     kOTProviderWillClose        = (OTEventCode)0x24000001,    /* Provider will close immediately        */
  611.     kOTProviderIsClosed            = (OTEventCode)0x24000002,    /* Provider was closed                    */
  612.     /*
  613.      * These are system events sent to registered clients
  614.      */
  615.         //
  616.         // result code is 0, cookie is the OTPortRef
  617.         //
  618.     kOTPortDisabled                = (OTEventCode)0x25000001,    /* Port is now disabled                    */
  619.     kOTPortEnabled                = (OTEventCode)0x25000002,    /* Port is now enabled                    */
  620.     kOTPortOffline                = (OTEventCode)0x25000003,    /* Port is now offline                    */
  621.     kOTPortOnline                = (OTEventCode)0x25000004,    /* Port is now online                    */
  622.         //
  623.         // result is a reason for the close request, cookie is a pointer to the 
  624.         // OTPortCloseStruct structure.
  625.         //
  626.     kOTClosePortRequest            = (OTEventCode)0x25000005,    /* Request to close/yield                */
  627.     kOTYieldPortRequest            = (OTEventCode)0x25000005,    /* Request to close/yield                */
  628.         //
  629.         // A new port has been registered, cookie is the OTPortRef
  630.         //
  631.     kOTNewPortRegistered        = (OTEventCode)0x25000006,    /* New port has been registered            */
  632.     /*
  633.      * These are events sent to the configuration management infrastructure 
  634.      */
  635.     kOTConfigurationChanged        = (OTEventCode)0x26000001,    /* Protocol configuration changed        */
  636.     kOTSystemSleep                = (OTEventCode)0x26000002,
  637.     kOTSystemShutdown            = (OTEventCode)0x26000003,
  638.     kOTSystemAwaken                = (OTEventCode)0x26000004,
  639.     kOTSystemIdle                = (OTEventCode)0x26000005,
  640.     kOTSystemSleepPrep            = (OTEventCode)0x26000006,
  641.     kOTSystemShutdownPrep        = (OTEventCode)0x26000007,
  642.     kOTSystemAwakenPrep            = (OTEventCode)0x26000008
  643. };
  644.  
  645. #define IsOTPrivateEvent(x)            (((x) & 0x70000000L) == kPRIVATEEVENT)
  646. #define IsOTCompleteEvent(x)        (((x) & 0x7f000000L) == kCOMPLETEEVENT)
  647. #define IsOTProtocolEvent(x)        (((x) & 0x7f000000L) == kPROTOCOLEVENT)
  648. #define IsOTStreamEvent(x)            (((x) & 0x7f000000L) == kSTREAMEVENT)
  649. #define IsOTSignalEvent(x)            (((x) & 0x7f000000L) == kSIGNALEVENT)
  650. #define GetOTEventCode(x)            (x)
  651.  
  652. /*    -------------------------------------------------------------------------
  653.     Signals that are generated by a stream.  Add these values to
  654.     kSIGNALEVENT to determine what event you are receiving.
  655.     ------------------------------------------------------------------------- */
  656.  
  657. enum
  658. {
  659.     SIGHUP        = 1,
  660.     SIGURG        = 16,
  661.     SIGPOLL        = 30
  662. };
  663.  
  664. /*    -------------------------------------------------------------------------
  665.     Option Management equates
  666.     ------------------------------------------------------------------------- */
  667. /*
  668. ** The XTI Level number of a protocol
  669. */
  670. typedef UInt32                OTXTILevel;
  671.  
  672.     enum
  673.     {
  674.         XTI_GENERIC     = (OTXTILevel)0xffff    /* level to match any protocol    */
  675.     };
  676. /*
  677. ** The XTI name of a protocol option
  678. */
  679. typedef UInt32                OTXTIName;
  680.     /*
  681.      * XTI names for options used with XTI_GENERIC above
  682.      */
  683.     enum
  684.     {
  685.         XTI_DEBUG        = (OTXTIName)0x0001,
  686.         XTI_LINGER        = (OTXTIName)0x0080,
  687.         XTI_RCVBUF        = (OTXTIName)0x1002,
  688.         XTI_RCVLOWAT    = (OTXTIName)0x1004,
  689.         XTI_SNDBUF        = (OTXTIName)0x1001,
  690.         XTI_SNDLOWAT    = (OTXTIName)0x1003,
  691.         XTI_PROTOTYPE    = (OTXTIName)0x1005
  692.     };
  693.     /*
  694.      * Generic options that can be used with any protocol
  695.      * that understands them
  696.      */
  697.     enum 
  698.     {
  699.         OPT_CHECKSUM    = (OTXTIName)0x0600,    // Set checksumming = UInt32 - 0 or 1)
  700.         OPT_RETRYCNT    = (OTXTIName)0x0601,    // Set a retry counter = UInt32 (0 = infinite)
  701.         OPT_INTERVAL    = (OTXTIName)0x0602,    // Set a retry interval = UInt32 milliseconds
  702.         OPT_ENABLEEOM    = (OTXTIName)0x0603,    // Enable the EOM indication = UInt8 (0 or 1)
  703.         OPT_SELFSEND    = (OTXTIName)0x0604,    // Enable Self-sending on broadcasts = UInt32 (0 or 1)
  704.         OPT_SERVERSTATUS= (OTXTIName)0x0605,    // Set Server Status (format is proto dependent)
  705.         OPT_ALERTENABLE    = (OTXTIName)0x0606,    // Enable/Disable protocol alerts
  706.         OPT_KEEPALIVE    = (OTXTIName)0x0008        // See t_keepalive structure
  707.     };
  708.  
  709. /*******************************************************************************
  710. ** Definitions not associated with a Typedef
  711. ********************************************************************************/
  712.  
  713. /*    -------------------------------------------------------------------------
  714.     IOCTL values for the OpenTransport system
  715.     ------------------------------------------------------------------------- */
  716.  
  717. #define    MIOC_CMD(t,v)    ((((t)&0xFF) << 8) | ((v)&0xFF))
  718.  
  719. enum
  720. {
  721.     MIOC_STREAMIO    = 'A',        /* Basic Stream ioctl() cmds - I_PUSH, I_LOOK, etc. */
  722.     MIOC_STRLOG        = 'b',        /* ioctl's for Mentat's log device */
  723.     MIOC_SAD        = 'g',        /* ioctl's for Mentat's sad module */
  724.     MIOC_TCP        = 'k',        /* tcp.h ioctl's */
  725.     MIOC_DLPI        = 'l',        /* dlpi.h additions */
  726.     MIOC_OT            = 'O',        /* ioctls for Open Transport    */
  727.     MIOC_ATALK        = 'T',        /* ioctl's for AppleTalk    */
  728.     MIOC_SRL        = 'U',        /* ioctl's for Serial        */
  729.     MIOC_CFIG        = 'z'        /* ioctl's for private configuration */
  730. };
  731.  
  732. enum
  733. {
  734.     I_OTGetMiscellaneousEvents    = ((MIOC_OT << 8) | 1),            /* sign up for Misc Events                    */
  735.     I_OTSetFramingType            = ((MIOC_OT << 8) | 2),            /* Set framing option for link                */
  736.         kOTGetFramingValue            = 0xffffffff,                /* Use this value to read framing            */
  737.     I_OTSetRawMode                = ((MIOC_OT << 8) | 3),            /* Set raw mode for link                    */
  738.         kOTSetRecvMode                = 0x1,
  739.         kOTSendErrorPacket            = 0x2,
  740.  
  741.     I_OTConnect                    = ((MIOC_OT << 8) | 4),            /* Generic connect request for links        */
  742.     I_OTDisconnect                = ((MIOC_OT << 8) | 5),            /* Generic disconnect request for links        */
  743.     I_OTScript                    = ((MIOC_OT << 8) | 6)            /* Send a script to a module                */
  744. };
  745. /*
  746.  * Structure for the I_OTScript Ioctl.
  747.  */
  748. struct OTScriptInfo
  749. {
  750.     UInt32    fScriptType;
  751.     void*    fTheScript;
  752.     UInt32    fScriptLength;
  753. };
  754. typedef struct OTScriptInfo    OTScriptInfo;
  755.     
  756. /*    -------------------------------------------------------------------------
  757.     Maximum size of a provider name, and maximum size of a STREAM module name.
  758.     This module name is smaller than the maximum size of a TProvider to allow
  759.     for 4 characters of extra "minor number" information that might be 
  760.     potentially in a TProvider name
  761.     ------------------------------------------------------------------------- */
  762.  
  763. enum
  764. {
  765.     kMaxModuleNameLength    = 31,
  766.     kMaxModuleNameSize        = kMaxModuleNameLength + 1,
  767.  
  768.     kMaxProviderNameLength    = kMaxModuleNameLength + 4,
  769.     kMaxProviderNameSize    = kMaxProviderNameLength + 1,
  770.     
  771.     kMaxSlotIDLength        = 7,
  772.     kMaxSlotIDSize            = 8,
  773.     
  774.     kMaxResourceInfoLength    = 31,
  775.     kMaxResourceInfoSize    = 32
  776. };
  777.  
  778. /*    -------------------------------------------------------------------------
  779.     These values are used in the "fields" parameter of the OTAlloc call
  780.     to define which fields of the structure should be allocated.
  781.     ------------------------------------------------------------------------- */
  782.  
  783. enum 
  784. {
  785.     T_ADDR            = 0x01,
  786.     T_OPT            = 0x02,
  787.     T_UDATA         = 0x04,
  788.     T_ALL            = 0xffff
  789. };
  790.  
  791. /*    -------------------------------------------------------------------------
  792.     These are the potential values returned by OTGetEndpointState and OTSync
  793.     which represent the state of an endpoint
  794.     ------------------------------------------------------------------------- */
  795.  
  796. enum
  797. {
  798.     T_UNINIT        = 0,    /* addition to standard xti.h    */
  799.     T_UNBND         = 1,    /* unbound                        */
  800.     T_IDLE            = 2,    /* idle                            */
  801.     T_OUTCON        = 3,    /* outgoing connection pending    */
  802.     T_INCON         = 4,    /* incoming connection pending    */
  803.     T_DATAXFER        = 5,    /* data transfer                */
  804.     T_OUTREL        = 6,    /* outgoing orderly release        */
  805.     T_INREL         = 7        /* incoming orderly release        */
  806. };
  807.  
  808. /*    -------------------------------------------------------------------------
  809.     Flags used by option management calls to request services
  810.     ------------------------------------------------------------------------- */
  811.  
  812. enum
  813. {
  814.     T_NEGOTIATE     = 0x004,
  815.     T_CHECK         = 0x008,
  816.     T_DEFAULT        = 0x010,
  817.     T_CURRENT        = 0x080
  818. };
  819.  
  820. /*    -------------------------------------------------------------------------
  821.     Flags used by option management calls to return results
  822.     ------------------------------------------------------------------------- */
  823.     
  824. enum
  825. {
  826.     T_SUCCESS        = 0x020,
  827.     T_FAILURE        = 0x040,
  828.     T_PARTSUCCESS    = 0x100,
  829.     T_READONLY        = 0x200,
  830.     T_NOTSUPPORT    = 0x400
  831. };
  832.  
  833. /*    -------------------------------------------------------------------------
  834.     General definitions
  835.     ------------------------------------------------------------------------- */
  836.  
  837. enum
  838. {
  839.     T_YES            = 1,
  840.     T_NO            = 0,
  841.     T_UNUSED        = -1,
  842.     T_NULL            = 0,
  843.     T_ABSREQ        = 0x8000
  844. };
  845.  
  846. /*    -------------------------------------------------------------------------
  847.     Option Management definitions
  848.     ------------------------------------------------------------------------- */
  849.  
  850. enum
  851. {
  852.     T_UNSPEC        = (~0 - 2),
  853.     T_ALLOPT        = 0
  854. };
  855. //
  856. // This macro will align return the value of "len", rounded up to the next
  857. // 4-byte boundary.
  858. //
  859. #define T_ALIGN(len)        (((UInt32)(len)+(sizeof(SInt32)-1)) & ~(sizeof(SInt32)-1))
  860. //
  861. // This macro will return the next option in the buffer, given the previous option
  862. // in the buffer, returning NULL if there are no more.
  863. // You start off by setting prevOption = (TOption*)theBuffer
  864. // (Use OTNextOption for a more thorough check - it ensures the end
  865. //  of the option is in the buffer as well.)
  866. //
  867. #define OPT_NEXTHDR(theBuffer, theBufLen, prevOption) \
  868.     (((char*)(prevOption) + T_ALIGN((prevOption)->len) < (char*)(theBuffer) + (theBufLen)) ?    \
  869.             (TOption*)((char*)(prevOption)+T_ALIGN((prevOption)->len))    \
  870.             : (TOption*)NULL)
  871.     
  872. /*******************************************************************************
  873. ** Structures and forward declarations
  874. **
  875. ** From here on down, all structures are aligned the same on 68K and powerpc
  876. ********************************************************************************/
  877.  
  878. /*    -------------------------------------------------------------------------
  879.     OTConfiguration structure - this is a "black box" structure used to
  880.     define the configuration of a provider or endpoint.
  881.     ------------------------------------------------------------------------- */
  882.  
  883. struct OTConfiguration;
  884. typedef struct OTConfiguration    OTConfiguration;
  885.  
  886. #define kOTInvalidConfigurationPtr        ((OTConfiguration*)-1L)
  887. #define kOTNoMemoryConfigurationPtr        ((OTConfiguration*)0)
  888.  
  889. /*    -------------------------------------------------------------------------
  890.     Option Management structures
  891.     ------------------------------------------------------------------------- */
  892. /*
  893.  * Structure used with OPT_KEEPALIVE option.
  894.  */
  895. struct t_kpalive
  896. {
  897.     long    kp_onoff;        /* option on/off        */
  898.     long    kp_timeout;        /* timeout in minutes    */
  899. };
  900. typedef struct t_kpalive t_kpalive;
  901.  
  902. /*
  903.  * Structure used with XTI_LINGER option
  904.  */
  905. struct t_linger 
  906. {
  907.     long    l_onoff;        /* option on/off */
  908.     long    l_linger;        /* linger time */
  909. };
  910. typedef struct t_linger t_linger;
  911.  
  912. /*    -------------------------------------------------------------------------
  913.     TEndpointInfo - this structure is returned from the GetEndpointInfo call
  914.     and contains information about an endpoint
  915.     ------------------------------------------------------------------------- */
  916.  
  917. struct t_info
  918. {
  919.     SInt32    addr;        /* Maximum size of an address            */
  920.     SInt32    options;    /* Maximum size of options                */
  921.     SInt32    tsdu;        /* Standard data transmit unit size        */
  922.     SInt32    etsdu;        /* Expedited data transmit unit size    */
  923.     SInt32    connect;    /* Maximum data size on connect            */
  924.     SInt32    discon;        /* Maximum data size on disconnect        */
  925.     UInt32    servtype;    /* service type (see below for values)    */
  926.     UInt32    flags;        /* Flags (see below for values)            */
  927. };
  928.  
  929. typedef struct t_info        TEndpointInfo;
  930.  
  931. /*
  932.  * Values returned in servtype field of TEndpointInfo
  933.  */
  934. enum
  935. {
  936.     T_COTS            = 1,    /* Connection-mode service                                */
  937.     T_COTS_ORD        = 2,    /* Connection service with orderly release                */
  938.     T_CLTS            = 3,    /* Connectionless-mode service                            */
  939.     T_TRANS            = 5,    /* Connection-mode transaction service                    */
  940.     T_TRANS_ORD        = 6,    /* Connection transaction service with orderly release    */
  941.     T_TRANS_CLTS    = 7        /* Connectionless transaction service                    */
  942. };
  943. /*
  944.  * Values returned in flags field of TEndpointInfo
  945.  */
  946. enum
  947. {
  948.     T_SENDZERO            = 0x001,            /* supports 0-length TSDU's                */
  949.     T_XPG4_1            = 0x002,            /* supports the GetProtAddress call        */
  950.     T_CAN_SUPPORT_MDATA    = 0x10000000,        /* support M_DATAs on packet protocols    */
  951.     T_CAN_RESOLVE_ADDR    = 0x40000000,        /* Supports ResolveAddress call            */
  952.     T_CAN_SUPPLY_MIB    = 0x20000000        /* Supports SNMP MIB data                */
  953. };
  954. /*
  955.  * Values returned in tsdu, etsdu, connect, and discon fields of TEndpointInfo
  956.  */
  957. enum
  958. {
  959.     T_INFINITE        = -1,    /* supports infinit amounts of data        */
  960.     T_INVALID        = -2    /* Does not support data transmission    */
  961. };
  962.  
  963. /*    -------------------------------------------------------------------------
  964.     OTPortRecord
  965.     ------------------------------------------------------------------------- */
  966. /*
  967.  * Unique identifier for a port
  968.  */
  969. typedef UInt32 OTPortRef;
  970.  
  971. /*
  972.  * A couple of special values for the "port type" in an OTPortRef.
  973.  * See OpenTptLinks.h for other values.
  974.  * The device kOTPseudoDevice is used where no other defined
  975.  * device type will work.
  976.  */
  977. enum
  978. {
  979.     kOTNoDeviceType        = 0,
  980.     kOTPseudoDevice        = 1023,
  981.     kOTLastDeviceIndex    = 1022,
  982.     
  983.     kOTLastSlotNumber    = 255,
  984.     kOTLastOtherNumber    = 255
  985. };
  986.  
  987. /*
  988.  * kMaxPortNameLength is the maximum size allowed to define
  989.  * a port
  990.  */
  991. enum
  992. {
  993.     kMaxPortNameLength        = kMaxModuleNameLength + 4,
  994.     kMaxPortNameSize        = kMaxPortNameLength + 1
  995. };
  996.  
  997. enum
  998. {
  999.     kOTInvalidPortRef    = ((OTPortRef)0)
  1000. };
  1001.  
  1002. /*
  1003.  * Equates for the legal Bus-type values
  1004.  */
  1005. enum
  1006. {
  1007.     kOTUnknownBusPort    = 0,
  1008.     kOTMotherboardBus    = 1,
  1009.     kOTNuBus            = 2,
  1010.     kOTPCIBus            = 3,
  1011.     kOTGeoPort            = 4,
  1012.     kOTPCCardBus        = 5,
  1013.     kOTFireWireBus        = 6,
  1014.     kOTLastBusIndex        = 15
  1015. };
  1016.  
  1017. struct OTPortCloseStruct
  1018. {
  1019.     OTPortRef            fPortRef;            // The port requested to be closed.
  1020.     ProviderRef            fTheProvider;        // The provider using the port.
  1021.     OSStatus            fDenyReason;        // Set to a negative number to deny the request
  1022. };
  1023.  
  1024. typedef struct OTPortCloseStruct    OTPortCloseStruct;
  1025.  
  1026. extern pascal OTPortRef    OTCreatePortRef(UInt8 busType, UInt16 devType,
  1027.                                         UInt16 slot, UInt16 other);
  1028. extern pascal UInt16    OTGetDeviceTypeFromPortRef(OTPortRef ref);
  1029. extern pascal UInt16    OTGetBusTypeFromPortRef(OTPortRef ref);
  1030. extern pascal UInt16    OTGetSlotFromPortRef(OTPortRef ref, UInt16* other);
  1031. extern pascal OTPortRef    OTSetDeviceTypeInPortRef(OTPortRef ref, UInt16 devType);
  1032. extern pascal OTPortRef    OTSetBusTypeInPortRef(OTPortRef ref, UInt8 busType);
  1033.  
  1034. #define OTCreateNuBusPortRef(devType, slot, other)    \
  1035.     OTCreatePortRef(kOTNuBus, devType, slot, other)
  1036.     
  1037. #define OTCreatePCIPortRef(devType, slot, other)    \
  1038.     OTCreatePortRef(kOTPCIBus, devType, slot, other)
  1039.     
  1040. #define OTCreatePCMCIAPortRef(devType, slot, other)    \
  1041.     OTCreatePortRef(kOTPCMCIABus, devType, slot, other)
  1042.  
  1043. /*    
  1044.  * One OTPortRecord is created for each instance of a port.
  1045.  * For Instance 'enet' identifies an ethernet port.
  1046.  * A TPortRecord for each ethernet card it finds, with an
  1047.  * OTPortRef that will uniquely allow the driver to determine which
  1048.  * port it is supposed to open on.
  1049.  */
  1050.  
  1051. struct OTPortRecord
  1052. {
  1053.     OTPortRef        fRef;
  1054.     UInt32            fPortFlags;
  1055.     UInt32            fInfoFlags;
  1056.     UInt32            fCapabilities;
  1057.     size_t            fNumChildPorts;
  1058.     OTPortRef*        fChildPorts;
  1059.     char            fPortName[kMaxProviderNameSize];
  1060.     char            fModuleName[kMaxModuleNameSize];
  1061.     char            fSlotID[kMaxSlotIDSize];
  1062.     char            fResourceInfo[kMaxResourceInfoSize];
  1063.     char            fReserved[164];
  1064. };
  1065.  
  1066. typedef struct OTPortRecord    OTPortRecord;
  1067.  
  1068. /*
  1069.  * Values for the fInfoFlags field of OTPortRecord
  1070.  * kOTPortCanYield and kOTPortCanArbitrate
  1071.  * will not be set until the port is used for the first time.
  1072.  */
  1073. enum
  1074. {
  1075.     kOTPortIsDLPI                = 0x00000001,
  1076.     kOTPortIsTPI                = 0x00000002,
  1077.     kOTPortCanYield                = 0x00000004,
  1078.     kOTPortCanArbitrate            = 0x00000008,
  1079.     kOTPortIsTransitory            = 0x00000010,
  1080.     kOTPortAutoConnects            = 0x00000020,
  1081.     kOTPortIsSystemRegistered    = 0x00004000,
  1082.     kOTPortIsPrivate            = 0x00008000,
  1083.     kOTPortIsAlias                = 0x80000000
  1084. };
  1085. /*
  1086.  * Values for the fPortFlags field of TPortRecord
  1087.  * If no bits are set, the port is currently inactive.
  1088.  */
  1089. enum
  1090. {
  1091.     kOTPortIsActive                = 0x00000001,
  1092.     kOTPortIsDisabled             = 0x00000002,
  1093.     kOTPortIsUnavailable        = 0x00000004,
  1094.     kOTPortIsOffline            = 0x00000008
  1095. };
  1096.  
  1097. /*    -------------------------------------------------------------------------
  1098.     TOptionHeader and TOption
  1099.     
  1100.     This structure describes the contents of a single option in a buffer
  1101.     ------------------------------------------------------------------------- */
  1102.  
  1103. struct TOptionHeader
  1104. {
  1105.         UInt32        len;        /* total length of option                */
  1106.                                 /* = sizeof(TOptionHeader) + length        */
  1107.                                 /*     of option value in bytes            */
  1108.         OTXTILevel    level;        /* protocol affected                    */
  1109.         OTXTIName    name;        /* option name                            */
  1110.         UInt32        status;     /* status value                            */
  1111. };
  1112.  
  1113. typedef struct TOptionHeader    TOptionHeader;
  1114.  
  1115. struct TOption
  1116. {
  1117.         UInt32        len;        /* total length of option                */
  1118.                                 /* = sizeof(TOption) + length    */
  1119.                                 /*     of option value in bytes            */
  1120.         OTXTILevel    level;        /* protocol affected                    */
  1121.         OTXTIName    name;        /* option name                            */
  1122.         UInt32        status;     /* status value                            */
  1123.         UInt32        value[1];    /* data goes here                        */
  1124. };
  1125.  
  1126. typedef struct TOption    TOption;
  1127.  
  1128. enum
  1129. {
  1130.     kOTOptionHeaderSize            = sizeof(TOptionHeader),
  1131.     kOTBooleanOptionDataSize    = sizeof(UInt32),
  1132.     kOTBooleanOptionSize        = kOTOptionHeaderSize + kOTBooleanOptionDataSize,
  1133.     kOTOneByteOptionSize        = kOTOptionHeaderSize + 1,
  1134.     kOTTwoByteOptionSize        = kOTOptionHeaderSize + 2,
  1135.     kOTFourByteOptionSize        = kOTOptionHeaderSize + sizeof(UInt32)
  1136. };
  1137.  
  1138. /*    -------------------------------------------------------------------------
  1139.     OTClientList structure
  1140.     
  1141.     This is used with the OTYieldPortRequest function.
  1142.     ------------------------------------------------------------------------- */
  1143.  
  1144. struct OTClientList
  1145. {
  1146.     size_t        fNumClients;
  1147.     UInt8        fBuffer[4];
  1148. };
  1149.  
  1150. typedef struct OTClientList    OTClientList;
  1151.  
  1152. /*    -------------------------------------------------------------------------
  1153.     OTData
  1154.     
  1155.     This is a structure that may be used in a TNetbuf or netbuf to send
  1156.     non-contiguous data.  Set the 'len' field of the netbuf to the
  1157.     constant kNetbufDataIsOTData to signal that the 'buf' field of the
  1158.     netbuf actually points to one of these structures instead of a
  1159.     memory buffer.
  1160.     ------------------------------------------------------------------------- */
  1161.  
  1162. struct OTData
  1163. {
  1164.         void*        fNext;
  1165.         void*        fData;
  1166.         size_t        fLen;
  1167. };
  1168.  
  1169. typedef struct OTData    OTData;
  1170.  
  1171. enum
  1172. {
  1173.     kNetbufDataIsOTData    = (size_t)0xfffffffeU
  1174. };
  1175.  
  1176. /*    -------------------------------------------------------------------------
  1177.     OTBuffer
  1178.  
  1179.     This is the structure that is used for no-copy receives.
  1180.     When you are done with it, you must call the OTReleaseBuffer function.
  1181.     For best performance, you need to call OTReleaseBuffer quickly.  Only
  1182.     data netbufs may use this - no netbufs for addresses or options, or the like.
  1183.     ------------------------------------------------------------------------- */
  1184.  
  1185. typedef struct OTBuffer    OTBuffer;
  1186.  
  1187. struct OTBuffer
  1188. {
  1189.         void*        fLink;        // b_next & b_prev
  1190.         void*        fLink2;
  1191.         OTBuffer*    fNext;        // b_cont
  1192.         UInt8*        fData;        // b_rptr
  1193.         size_t        fLen;        // b_wptr
  1194.         void*        fSave;        // b_datap
  1195.         UInt8        fBand;        // b_band
  1196.         UInt8        fType;        // b_pad1
  1197.         UInt8        fPad1;
  1198.         UInt8        fFlags;        // b_flag
  1199. };
  1200.  
  1201. /*    -------------------------------------------------------------------------
  1202.     OTBufferInfo
  1203.     
  1204.     This structure is used with OTReadBuffer to keep track of where you
  1205.     are in the buffer, since the OTBuffer is "read-only".
  1206.     ------------------------------------------------------------------------- */
  1207.  
  1208. struct OTBufferInfo
  1209. {
  1210.     OTBuffer*    fBuffer;
  1211.     size_t        fOffset;
  1212.     UInt8        fPad;
  1213. };
  1214.  
  1215. typedef struct OTBufferInfo    OTBufferInfo;
  1216.  
  1217. #define OTInitBufferInfo(infoPtr, theBuffer)    \
  1218.     (infoPtr)->fBuffer = theBuffer;                \
  1219.     (infoPtr)->fPad    = (theBuffer)->fPad1;        \
  1220.     (infoPtr)->fOffset    = 0
  1221.  
  1222. enum
  1223. {
  1224.     kOTNetbufDataIsOTBufferStar    = (size_t)0xfffffffdU
  1225. };
  1226.  
  1227. /*    -------------------------------------------------------------------------
  1228.     TNetbuf
  1229.     
  1230.     This structure is the basic structure used to pass data back and forth
  1231.     between the Open Transport protocols and their clients
  1232.     ------------------------------------------------------------------------- */
  1233.  
  1234. struct TNetbuf
  1235. {
  1236.     size_t    maxlen;
  1237.     size_t    len;
  1238.     UInt8*    buf;
  1239. };
  1240.  
  1241. typedef struct TNetbuf    TNetbuf;
  1242.  
  1243. /*    -------------------------------------------------------------------------
  1244.     TBind
  1245.     
  1246.     Structure passed to GetProtAddress, ResolveAddress and Bind
  1247.     ------------------------------------------------------------------------- */
  1248.  
  1249. struct TBind
  1250. {
  1251.     TNetbuf    addr;
  1252.     OTQLen    qlen;
  1253. };
  1254.  
  1255. typedef struct TBind    TBind;
  1256.  
  1257. /*    -------------------------------------------------------------------------
  1258.     TDiscon
  1259.     
  1260.     Structure passed to RcvDisconnect to find out additional information
  1261.     about the disconnect
  1262.     ------------------------------------------------------------------------- */
  1263.  
  1264. struct TDiscon
  1265. {
  1266.     TNetbuf        udata;
  1267.     OTReason    reason;
  1268.     OTSequence     sequence;
  1269. };
  1270.  
  1271. typedef struct TDiscon    TDiscon;
  1272.  
  1273.  
  1274. /*    -------------------------------------------------------------------------
  1275.     TCall
  1276.     
  1277.     Structure passed to Connect, RcvConnect, Listen, Accept, and
  1278.     SndDisconnect to describe the connection.
  1279.     ------------------------------------------------------------------------- */
  1280.  
  1281. struct TCall
  1282. {
  1283.     TNetbuf        addr;
  1284.     TNetbuf        opt;
  1285.     TNetbuf        udata;
  1286.     OTSequence     sequence;
  1287. };
  1288.  
  1289. typedef struct TCall    TCall;
  1290.     
  1291. /*    -------------------------------------------------------------------------
  1292.     TUnitData
  1293.     
  1294.     Structure passed to SndUData and RcvUData to describe the datagram
  1295.     ------------------------------------------------------------------------- */
  1296.  
  1297. struct TUnitData
  1298. {
  1299.     TNetbuf            addr;
  1300.     TNetbuf            opt;
  1301.     TNetbuf            udata;
  1302. };
  1303.  
  1304. typedef struct TUnitData    TUnitData;
  1305.     
  1306. /*    -------------------------------------------------------------------------
  1307.     TUDErr
  1308.     
  1309.     Structure passed to RcvUDErr to find out about a datagram error
  1310.     ------------------------------------------------------------------------- */
  1311.  
  1312. struct TUDErr
  1313. {
  1314.     TNetbuf            addr;
  1315.     TNetbuf            opt;
  1316.     SInt32            error;
  1317. };
  1318.  
  1319. typedef struct TUDErr    TUDErr;
  1320.  
  1321. /*    -------------------------------------------------------------------------
  1322.     TOptMgmt
  1323.     
  1324.     Structure passed to the OptionManagement call to read or set protocol
  1325.     options.
  1326.     ------------------------------------------------------------------------- */
  1327.  
  1328. struct TOptMgmt
  1329. {
  1330.     TNetbuf            opt;
  1331.     OTFlags            flags;
  1332. };
  1333.  
  1334. typedef struct TOptMgmt    TOptMgmt;
  1335.  
  1336. /*    -------------------------------------------------------------------------
  1337.     TRequest
  1338.     
  1339.     Structure passed to SndRequest and RcvRequest that contains the information
  1340.     about the request
  1341.     ------------------------------------------------------------------------- */
  1342.  
  1343. struct TRequest
  1344. {
  1345.     TNetbuf            data;
  1346.     TNetbuf            opt;
  1347.     OTSequence        sequence;
  1348. };
  1349.  
  1350. typedef struct TRequest    TRequest;
  1351.  
  1352. /*    -------------------------------------------------------------------------
  1353.     TReply
  1354.     
  1355.     Structure passed to SndReply to send a reply to an incoming request
  1356.     ------------------------------------------------------------------------- */
  1357.  
  1358. struct TReply
  1359. {
  1360.     TNetbuf            data;
  1361.     TNetbuf            opt;
  1362.     OTSequence        sequence;
  1363. };
  1364.  
  1365. typedef struct TReply    TReply;
  1366.  
  1367. /*    -------------------------------------------------------------------------
  1368.     TUnitRequest
  1369.     
  1370.     Structure passed to SndURequest and RcvURequest that contains the information
  1371.     about the request
  1372.     ------------------------------------------------------------------------- */
  1373.  
  1374. struct TUnitRequest
  1375. {
  1376.     TNetbuf            addr;
  1377.     TNetbuf            opt;
  1378.     TNetbuf            udata;
  1379.     OTSequence        sequence;
  1380. };
  1381.  
  1382. typedef struct TUnitRequest    TUnitRequest;
  1383.  
  1384. /*    -------------------------------------------------------------------------
  1385.     TUnitReply
  1386.     
  1387.     Structure passed to SndUReply to send a reply to an incoming request
  1388.     ------------------------------------------------------------------------- */
  1389.  
  1390. struct TUnitReply
  1391. {
  1392.     TNetbuf            opt;
  1393.     TNetbuf            udata;
  1394.     OTSequence        sequence;
  1395. };
  1396.  
  1397. typedef struct TUnitReply    TUnitReply;
  1398.  
  1399. /*    -------------------------------------------------------------------------
  1400.     TRegisterRequest
  1401.     ------------------------------------------------------------------------- */
  1402.  
  1403. struct TRegisterRequest
  1404. {
  1405.     TNetbuf        name;
  1406.     TNetbuf        addr;
  1407.     OTFlags        flags;
  1408. };
  1409.  
  1410. typedef struct TRegisterRequest    TRegisterRequest;
  1411.     
  1412. /*    -------------------------------------------------------------------------
  1413.     TRegisterReply
  1414.     ------------------------------------------------------------------------- */
  1415.  
  1416. struct TRegisterReply
  1417. {
  1418.     TNetbuf        addr;
  1419.     OTNameID    nameid;
  1420. };
  1421.  
  1422. typedef struct TRegisterReply    TRegisterReply;
  1423.     
  1424. /*    -------------------------------------------------------------------------
  1425.     TLookupRequest
  1426.     ------------------------------------------------------------------------- */
  1427.  
  1428. struct TLookupRequest
  1429. {
  1430.     TNetbuf        name;
  1431.     TNetbuf        addr;
  1432.     UInt32        maxcnt;
  1433.     OTTimeout    timeout;
  1434.     OTFlags        flags;
  1435. };
  1436.  
  1437. typedef struct TLookupRequest    TLookupRequest;
  1438.  
  1439. /*    -------------------------------------------------------------------------
  1440.     TLookupReply 
  1441.     
  1442.     Structure used by Mapper protocols to return the results of name Lookups
  1443.     ------------------------------------------------------------------------- */
  1444.  
  1445. struct TLookupBuffer
  1446. {
  1447.     UInt16        fAddressLength;
  1448.     UInt16        fNameLength;
  1449.     UInt8        fAddressBuffer[1];
  1450. };
  1451.  
  1452. typedef struct TLookupBuffer    TLookupBuffer;
  1453.  
  1454. #define OTNextLookupBuffer(buf)            \
  1455.     ((TLookupBuffer*)                    \
  1456.         ((char*)buf + ((offsetof(TLookupBuffer, fAddressBuffer) + buf->fAddressLength + buf->fNameLength + 3) & ~3)))
  1457.  
  1458. struct TLookupReply
  1459. {
  1460.     TNetbuf            names;
  1461.     UInt32            rspcount;
  1462. };
  1463.  
  1464. typedef struct TLookupReply    TLookupReply;
  1465.  
  1466. /*******************************************************************************
  1467. ** C Interfaces to Open Transport
  1468. ********************************************************************************/
  1469.  
  1470. /*    -------------------------------------------------------------------------
  1471.     Initializing and shutting down Open Transport
  1472.     ------------------------------------------------------------------------- */
  1473.     
  1474. #if !OTKERNEL
  1475.  
  1476. extern pascal OSStatus    InitOpenTransport(void);
  1477. extern pascal OSStatus    InitOpenTransportUtilities(void);
  1478. extern pascal void        CloseOpenTransport(void);
  1479. //
  1480. // This registers yourself as a client for any miscellaneous Open Transport
  1481. // notifications that come along. CloseOpenTransport will automatically do
  1482. // an OTUnregisterAsClient, if you have not already done so.
  1483. //
  1484. extern pascal OSStatus    OTRegisterAsClient(OTClientName name, OTNotifyProcPtr proc);
  1485. extern pascal OSStatus    OTUnregisterAsClient(void);
  1486.  
  1487. #endif    /* !OTKERNEL    */
  1488.  
  1489. /*    -------------------------------------------------------------------------
  1490.      Tasking model routines
  1491.     ------------------------------------------------------------------------- */
  1492. //
  1493. // These are normally used by the kernel to tell Open Transport we're
  1494. // at interrupt time.
  1495. //
  1496. extern pascal void        OTEnterInterrupt(void);
  1497. extern pascal void        OTLeaveInterrupt(void);
  1498.  
  1499.     /*
  1500.      * Function definition to handle process routine callbacks
  1501.      *
  1502.      * This is never a UniversalProcPtr.
  1503.      */
  1504.     typedef pascal void (*OTProcessProcPtr)(void* arg);
  1505.  
  1506. extern pascal long        OTCreateDeferredTask(OTProcessProcPtr proc, void* arg);
  1507. extern pascal Boolean    OTScheduleDeferredTask(long dtCookie);
  1508. extern pascal Boolean    OTScheduleInterruptTask(long dtCookie);
  1509. extern pascal OSStatus    OTDestroyDeferredTask(long dtCookie);
  1510.  
  1511. #if !OTKERNEL
  1512.  
  1513. extern pascal long        OTCreateSystemTask(OTProcessProcPtr proc, void* arg);
  1514. extern pascal OSStatus    OTDestroySystemTask(long stCookie);
  1515. extern pascal Boolean    OTScheduleSystemTask(long stCookie);
  1516. extern pascal Boolean    OTCancelSystemTask(long stCookie);
  1517. extern pascal Boolean    OTCanMakeSyncCall(void);
  1518.  
  1519. #endif    /* !OTKERNEL    */
  1520.  
  1521. extern Boolean            OTIsAtInterruptLevel(void);
  1522. extern Boolean            OTCanLoadLibraries(void);
  1523.     
  1524. /*    -------------------------------------------------------------------------
  1525.     Functions for dealing with port
  1526.     ------------------------------------------------------------------------- */
  1527.  
  1528. #if !OTKERNEL
  1529.     //
  1530.     // Index through the ports in the system
  1531.     //
  1532. extern pascal Boolean    OTGetIndexedPort(OTPortRecord* record, size_t index);
  1533.     //
  1534.     // Find an OTPortRecord for a port using it's name
  1535.     //
  1536. extern pascal Boolean    OTFindPort(OTPortRecord* record, const char* portName);
  1537.     //
  1538.     // Find an OTPortRecord for a port using it's OTPortRef
  1539.     //
  1540. extern pascal Boolean    OTFindPortByRef(OTPortRecord* record, OTPortRef ref);
  1541.     //
  1542.     // Register a port. The name the port was registered under is returned in
  1543.     // the fPortName field.
  1544.     //
  1545. extern OSStatus    OTRegisterPort(OTPortRecord* portInfo, void* ref);
  1546.     //
  1547.     // Unregister the port with the given name (If you re-register the
  1548.     // port, it may get a different name - use OTChangePortState if
  1549.     // that is not desireable).  Since a single OTPortRef can be registered
  1550.     // with several names, the API needs to use the portName rather than
  1551.     // the OTPortRef to disambiguate.
  1552.     //
  1553. extern OSStatus    OTUnregisterPort(const char* portName, void**);
  1554.     //
  1555.     // Change the state of the port.
  1556.     //
  1557. extern OSStatus    OTChangePortState(OTPortRef, OTEventCode theChange, OTResult why);
  1558.  
  1559. #endif    /* !OTKERNEL    */
  1560.  
  1561. /*    -------------------------------------------------------------------------
  1562.     Interface to providers
  1563.     ------------------------------------------------------------------------- */
  1564.  
  1565. #if !OTKERNEL
  1566.  
  1567. extern pascal OSStatus        OTAsyncOpenProvider(OTConfiguration*, OTOpenFlags,
  1568.                                                 OTNotifyProcPtr, void*);
  1569. extern pascal ProviderRef    OTOpenProvider(OTConfiguration*, OTOpenFlags, OSStatus*);
  1570. extern pascal OSStatus        OTCloseProvider(ProviderRef ref);
  1571. extern pascal ProviderRef    OTTransferProviderOwnership(ProviderRef ref, 
  1572.                                                         OTClient prevOwner,
  1573.                                                         OSStatus* errPtr);
  1574. extern pascal OTClient    OTWhoAmI(void);
  1575. extern pascal OTPortRef    OTGetProviderPortRef(ProviderRef ref);
  1576. extern pascal SInt32    OTIoctl(ProviderRef ref, UInt32 cmd, void* data);
  1577. extern pascal OTResult    OTGetMessage(ProviderRef ref, struct strbuf* ctlbuf,
  1578.                                      struct strbuf* databuf, OTFlags*);
  1579. extern pascal OTResult    OTGetPriorityMessage(ProviderRef ref, struct strbuf* ctlbuf,
  1580.                                              struct strbuf* databuf, OTBand*, OTFlags*);
  1581. extern pascal OSStatus    OTPutMessage(ProviderRef ref, const struct strbuf* ctlbuf,
  1582.                                      const struct strbuf* databuf, OTFlags flags);
  1583. extern pascal OSStatus    OTPutPriorityMessage(ProviderRef ref, const struct strbuf* ctlbuf,
  1584.                                              const struct strbuf* databuf, OTBand, OTFlags);
  1585. extern pascal OSStatus    OTSetAsynchronous(ProviderRef ref);
  1586. extern pascal OSStatus    OTSetSynchronous(ProviderRef ref);
  1587. extern pascal Boolean    OTIsSynchronous(ProviderRef ref);
  1588. extern pascal OSStatus    OTSetBlocking(ProviderRef ref);
  1589. extern pascal OSStatus    OTSetNonBlocking(ProviderRef ref);
  1590. extern pascal Boolean    OTIsBlocking(ProviderRef ref);
  1591. extern pascal OSStatus    OTInstallNotifier(ProviderRef ref,
  1592.                                           OTNotifyProcPtr proc, void* contextPtr);
  1593. extern pascal OSStatus    OTUseSyncIdleEvents(ProviderRef ref, Boolean useEvents);
  1594. extern pascal void        OTRemoveNotifier(ProviderRef ref);
  1595. extern pascal void        OTLeaveNotifier(ProviderRef ref);
  1596. extern pascal Boolean    OTEnterNotifier(ProviderRef ref);
  1597. extern pascal OSStatus    OTAckSends(ProviderRef ref);
  1598. extern pascal OSStatus    OTDontAckSends(ProviderRef ref);
  1599. extern pascal Boolean    OTIsAckingSends(ProviderRef ref);
  1600. extern pascal OSStatus    OTCancelSynchronousCalls(ProviderRef ref, OSStatus err);
  1601.  
  1602. #define OTIsNonBlocking(ref)    (!OTIsBlocking(ref))
  1603. #define OTIsAsynchronous(ref)    (!OTIsSynchronous(ref))
  1604.     
  1605. #endif    /* !OTKERNEL    */
  1606.  
  1607. /*    -------------------------------------------------------------------------
  1608.     Interface to endpoints
  1609.     ------------------------------------------------------------------------- */
  1610.  
  1611. #if !OTKERNEL
  1612. //
  1613. // Open/Close
  1614. //
  1615. extern pascal EndpointRef    
  1616.                         OTOpenEndpoint(OTConfiguration* config, OTOpenFlags oflag,
  1617.                                        TEndpointInfo* info, OSStatus* err);
  1618. extern pascal OSStatus    OTAsyncOpenEndpoint(OTConfiguration* config,
  1619.                                             OTOpenFlags oflag, TEndpointInfo* info,
  1620.                                             OTNotifyProcPtr proc, void* contextPtr);
  1621. //
  1622. // Misc Information
  1623. //
  1624. extern pascal OSStatus    OTGetEndpointInfo(EndpointRef ref, TEndpointInfo* info);
  1625. extern pascal OTResult    OTGetEndpointState(EndpointRef ref);
  1626. extern pascal OTResult    OTLook(EndpointRef ref);
  1627. extern pascal OTResult    OTSync(EndpointRef ref);
  1628. extern pascal OTResult    OTCountDataBytes(EndpointRef ref, size_t* countPtr);
  1629. extern pascal OSStatus    OTGetProtAddress(EndpointRef ref, TBind* boundAddr,
  1630.                                          TBind* peerAddr);
  1631. extern pascal OSStatus    OTResolveAddress(EndpointRef ref, TBind* reqAddr,
  1632.                                          TBind* retAddr, OTTimeout timeOut);
  1633. //
  1634. // Allocating structures
  1635. //
  1636. extern pascal void*        OTAlloc(EndpointRef ref, OTStructType structType,
  1637.                                 UInt32 fields, OSStatus* err);
  1638. extern pascal OTResult    OTFree(void* ptr, OTStructType structType);
  1639. //
  1640. // Option management
  1641. //
  1642. extern pascal OSStatus    OTOptionManagement(EndpointRef ref, TOptMgmt* req, TOptMgmt* ret);
  1643. //
  1644. // Bind/Unbind
  1645. //
  1646. extern pascal OSStatus    OTBind(EndpointRef ref, TBind* reqAddr, TBind* retAddr);
  1647. extern pascal OSStatus    OTUnbind(EndpointRef ref);
  1648. //
  1649. // Connection creation/tear-down
  1650. //
  1651. extern pascal OSStatus    OTConnect(EndpointRef ref, TCall* sndCall, TCall* rcvCall);
  1652. extern pascal OSStatus    OTRcvConnect(EndpointRef ref, TCall* call);
  1653. extern pascal OSStatus    OTListen(EndpointRef ref, TCall* call);
  1654. extern pascal OSStatus    OTAccept(EndpointRef ref, EndpointRef resRef, TCall* call);
  1655. extern pascal OSStatus    OTSndDisconnect(EndpointRef ref, TCall* call);
  1656. extern pascal OSStatus    OTSndOrderlyDisconnect(EndpointRef ref);
  1657. extern pascal OSStatus    OTRcvDisconnect(EndpointRef ref, TDiscon* discon);
  1658. extern pascal OSStatus    OTRcvOrderlyDisconnect(EndpointRef ref);
  1659. //
  1660. // Connection-oriented send/receive
  1661. //
  1662. extern pascal OTResult    OTRcv(EndpointRef ref, void* buf, size_t nbytes, OTFlags* flags);
  1663. extern pascal OTResult    OTSnd(EndpointRef ref, void* buf, size_t nbytes, OTFlags flags);
  1664. //
  1665. // non-connection oriented send/receive
  1666. //
  1667. extern pascal OSStatus    OTSndUData(EndpointRef ref, TUnitData* udata);
  1668. extern pascal OSStatus    OTRcvUData(EndpointRef ref, TUnitData* udata, OTFlags* flags);
  1669. extern pascal OSStatus    OTRcvUDErr(EndpointRef ref, TUDErr* uderr);
  1670. //
  1671. // Connection-oriented transactions
  1672. //
  1673. extern pascal OSStatus    OTSndRequest(EndpointRef ref, TRequest* req, OTFlags reqFlags);
  1674. extern pascal OSStatus    OTRcvReply(EndpointRef ref, TReply* reply, OTFlags* replyFlags);
  1675. extern pascal OSStatus    OTSndReply(EndpointRef ref, TReply* reply, OTFlags replyFlags);
  1676. extern pascal OSStatus    OTRcvRequest(EndpointRef ref, TRequest* req, OTFlags* reqFlags);
  1677. extern pascal OSStatus    OTCancelRequest(EndpointRef ref, OTSequence sequence);
  1678. extern pascal OSStatus    OTCancelReply(EndpointRef ref, OTSequence sequence);
  1679. //
  1680. // Connectionless transactions
  1681. //
  1682. extern pascal OSStatus    OTSndURequest(EndpointRef ref, TUnitRequest* req, OTFlags reqFlags);
  1683. extern pascal OSStatus    OTRcvUReply(EndpointRef ref, TUnitReply* reply, OTFlags* replyFlags);
  1684. extern pascal OSStatus    OTSndUReply(EndpointRef ref, TUnitReply* reply, OTFlags replyFlags);
  1685. extern pascal OSStatus    OTRcvURequest(EndpointRef ref, TUnitRequest* req, OTFlags* reqFlags);
  1686. extern pascal OSStatus    OTCancelURequest(EndpointRef ref, OTSequence seq);
  1687. extern pascal OSStatus    OTCancelUReply(EndpointRef ref, OTSequence seq);
  1688.  
  1689. /*    -------------------------------------------------------------------------
  1690.     Interface to mappers
  1691.     ------------------------------------------------------------------------- */
  1692.  
  1693. extern pascal OSStatus     OTAsyncOpenMapper(OTConfiguration* config, OTOpenFlags oflag,
  1694.                                           OTNotifyProcPtr proc, void* contextPtr);            
  1695. extern pascal MapperRef    OTOpenMapper(OTConfiguration* config, OTOpenFlags oflag,
  1696.                                      OSStatus* err);    
  1697. extern pascal OSStatus    OTRegisterName(MapperRef ref, TRegisterRequest* req,
  1698.                                        TRegisterReply* reply);
  1699. extern pascal OSStatus    OTDeleteName(MapperRef ref, TNetbuf* name);
  1700. extern pascal OSStatus    OTDeleteNameByID(MapperRef ref, OTNameID nameID);
  1701. extern pascal OSStatus    OTLookupName(MapperRef ref, TLookupRequest* req,
  1702.                                      TLookupReply* reply);
  1703.  
  1704. /*    -------------------------------------------------------------------------
  1705.     Miscellaneous and generic functions
  1706.     ------------------------------------------------------------------------- */
  1707.  
  1708. extern void*            OTAllocMem(size_t);
  1709. extern void                OTFreeMem(void*);
  1710. extern pascal void        OTDelay(UInt32 seconds);
  1711. extern pascal void        OTIdle(void);
  1712.  
  1713. extern pascal OTConfiguration*    
  1714.                         OTCreateConfiguration(const char* path);
  1715. extern pascal OTConfiguration*
  1716.                         OTCloneConfiguration(OTConfiguration* cfig);
  1717. extern pascal void        OTDestroyConfiguration(OTConfiguration* cfig);
  1718. extern pascal OSStatus    OTCreateOptions(const char* endPtName, char** strPtr,
  1719.                                         TNetbuf* buf);
  1720. extern pascal OSStatus    OTCreateOptionString(const char* endPtName, TOption** opt,
  1721.                                              void* bufEnd, char* string,
  1722.                                              size_t stringSize);
  1723.  
  1724. extern pascal OSStatus    OTNextOption(UInt8* buffer, UInt32 buflen,
  1725.                                      TOption** prevOptPtr);
  1726. extern pascal TOption*    OTFindOption(UInt8* buffer, UInt32 buflen,
  1727.                                      OTXTILevel level, OTXTIName name); 
  1728.         
  1729. #endif    /* !OTKERNEL    */
  1730.  
  1731. /*******************************************************************************
  1732. ** Open Transport Utility routines
  1733. **
  1734. ** These routines are available to both client and kernel
  1735. ********************************************************************************/
  1736.  
  1737. /*    -------------------------------------------------------------------------
  1738.     ** Memory functions
  1739.     ------------------------------------------------------------------------- */
  1740.  
  1741. extern void        OTMemcpy(void* dest, const void* src, size_t nBytes);
  1742. extern Boolean    OTMemcmp(const void* mem1, const void* mem2, size_t nBytes);
  1743. extern void        OTMemmove(void* dest, const void* src, size_t nBytes);
  1744. extern void        OTMemzero(void* dest, size_t nBytes);
  1745. extern void        OTMemset(void* dest, uchar_p toSet, size_t nBytes);
  1746. extern size_t    OTStrLength(const char*);
  1747. extern void        OTStrCopy(char*, const char*);
  1748. extern void        OTStrCat(char*, const char*);
  1749. extern Boolean    OTStrEqual(const char*, const char*);
  1750.  
  1751. /*    -------------------------------------------------------------------------
  1752.     ** Time functions
  1753.     **    
  1754.     **    OTGetTimeStamp returns time in "tick" numbers, stored in 64 bits.
  1755.     **    This timestamp can be used as a base number for calculating elapsed 
  1756.     **    time.
  1757.     **    OTSubtractTimeStamps returns a pointer to the "result" parameter.
  1758.     **        
  1759.     **    OTGetClockTimeInSecs returns time since Open Transport was initialized
  1760.     **        in seconds.
  1761.     ------------------------------------------------------------------------- */
  1762.     
  1763. typedef UnsignedWide    OTTimeStamp;
  1764.  
  1765. extern void            OTGetTimeStamp(OTTimeStamp*);
  1766. extern OTTimeStamp*    OTSubtractTimeStamps(OTTimeStamp* result, OTTimeStamp* start,
  1767.                                          OTTimeStamp* end);
  1768. extern UInt32        OTTimeStampInMilliseconds(OTTimeStamp* delta);
  1769. extern UInt32        OTTimeStampInMicroseconds(OTTimeStamp* delta);
  1770. extern UInt32        OTElapsedMilliseconds(OTTimeStamp* startTime);
  1771. extern UInt32        OTElapsedMicroseconds(OTTimeStamp* startTime);
  1772.  
  1773. extern UInt32        OTGetClockTimeInSecs(void);
  1774.  
  1775. /*    -------------------------------------------------------------------------
  1776.     ** OTLIFO
  1777.     **
  1778.     ** These are functions to implement a LIFO list that is interrupt-safe.
  1779.     ** The only function which is not is OTReverseList.  Normally, you create
  1780.     ** a LIFO list, populate it at interrupt time, and then use OTLIFOStealList
  1781.     ** to atomically remove the list, and OTReverseList to flip the list so that
  1782.     ** it is a FIFO list, which tends to be more useful.
  1783.     ------------------------------------------------------------------------- */
  1784.  
  1785. typedef struct OTLink    OTLink;
  1786. typedef struct OTLIFO    OTLIFO;
  1787.  
  1788. struct OTLink
  1789. {
  1790.     OTLink*    fNext;
  1791.     
  1792. #ifdef __cplusplus
  1793.             void    Init()
  1794.                         { fNext = NULL; }
  1795. #endif
  1796. };
  1797.  
  1798.     //
  1799.     // This function puts "object" on the listHead, and places the
  1800.     // previous value at listHead into the pointer at "object" plus
  1801.     // linkOffset.
  1802.     //
  1803. extern void        OTEnqueue(void** listHead, void* object, size_t linkOffset);
  1804.     //
  1805.     // This function returns the head object of the list, and places
  1806.     // the pointer at "object" + linkOffset into the listHead
  1807.     //
  1808. extern void*    OTDequeue(void** listHead, size_t linkOffset);
  1809.     //
  1810.     // This function atomically enqueues the link onto the list
  1811.     //
  1812. extern void     OTLIFOEnqueue(OTLIFO* list, OTLink* link);
  1813.     //
  1814.     // This function atomically dequeues the first element
  1815.     // on the list
  1816.     //
  1817. extern OTLink* OTLIFODequeue(OTLIFO* list);
  1818.     //
  1819.     // This function atomically empties the list and returns a
  1820.     // pointer to the first element on the list
  1821.     //
  1822. extern OTLink*    OTLIFOStealList(OTLIFO* list);
  1823.     //
  1824.     // This function reverses a list that was stolen by
  1825.     // OTLIFOStealList.  It is NOT atomic.  It returns the
  1826.     // new starting list.
  1827.     //
  1828. extern OTLink*    OTReverseList(OTLink*);
  1829.  
  1830. struct OTLIFO
  1831. {
  1832.     OTLink*    fHead;
  1833.     
  1834. #ifdef __cplusplus
  1835.                 void    Init()    
  1836.                             { fHead = NULL; }
  1837.                 
  1838.                 void    Enqueue(OTLink* link)
  1839.                             { OTLIFOEnqueue(this, link); }
  1840.                             
  1841.                 OTLink*    Dequeue()
  1842.                             { return OTLIFODequeue(this); }
  1843.                             
  1844.                 OTLink*    StealList()
  1845.                             { return OTLIFOStealList(this); }
  1846.                             
  1847.                 Boolean    IsEmpty()
  1848.                             { return fHead == NULL; }
  1849. #endif
  1850. };
  1851.  
  1852. /*    -------------------------------------------------------------------------
  1853.     ** OTList
  1854.     **
  1855.     ** An OTList is a non-interrupt-safe list, but has more features than the
  1856.     ** OTLIFO list. It is a standard singly-linked list.
  1857.     ------------------------------------------------------------------------- */
  1858.  
  1859. typedef struct OTList    OTList;
  1860.  
  1861.     /*
  1862.      * Function definition to handle notification from providers
  1863.      *
  1864.      * For PowerPC, this should never be a UniversalProcPtr.
  1865.      * For standard 68K runtime, this should never be a UniversalProcPtr.
  1866.      * For CFM68K, it MUST be a UniversalProcPtr.
  1867.      */
  1868.     typedef Boolean (*OTListSearchProcPtr)(const void* ref, OTLink* linkToCheck);
  1869.     //
  1870.     // Add the link to the list at the front
  1871.     //
  1872. extern void         OTAddFirst(OTList* list, OTLink* link);
  1873.     //
  1874.     // Add the link to the list at the end
  1875.     //
  1876. extern void         OTAddLast(OTList* list, OTLink* link);
  1877.     //
  1878.     // Remove the first link from the list
  1879.     //
  1880. extern OTLink*        OTRemoveFirst(OTList* list);
  1881.     //
  1882.     // Remove the last link from the list
  1883.     //
  1884. extern OTLink*        OTRemoveLast(OTList* list);
  1885.     //
  1886.     // Return the first link from the list
  1887.     //
  1888. extern OTLink*        OTGetFirst(OTList* list);
  1889.     //
  1890.     // Return the last link from the list
  1891.     //
  1892. extern OTLink*        OTGetLast(OTList* list);
  1893.     //
  1894.     // Return true if the link is present in the list
  1895.     //
  1896. extern Boolean        OTIsInList(OTList* list, OTLink* link);
  1897.     //
  1898.     // Find a link in the list which matches the search criteria
  1899.     // established by the search proc and the refPtr.  This is done
  1900.     // by calling the search proc, passing it the refPtr and each
  1901.     // link in the list, until the search proc returns true.
  1902.     // NULL is returned if the search proc never returned true.
  1903.     //
  1904. extern OTLink*        OTFindLink(OTList* list, OTListSearchProcPtr proc, const void* refPtr);
  1905.     //
  1906.     // Remove the specified link from the list, returning true if it was found
  1907.     //
  1908. extern Boolean        OTRemoveLink(OTList*, OTLink*);
  1909.     //
  1910.     // Similar to OTFindLink, but it also removes it from the list.
  1911.     //
  1912. extern OTLink*        OTFindAndRemoveLink(OTList* list, OTListSearchProcPtr proc, const void* refPtr);
  1913.     //
  1914.     // Return the "index"th link in the list
  1915.     //
  1916. extern OTLink*        OTGetIndexedLink(OTList* list, size_t index);
  1917.  
  1918. struct OTList
  1919. {
  1920.     OTLink*        fHead;
  1921.     
  1922. #ifdef __cplusplus
  1923.             void        Init()    
  1924.                             { fHead = NULL; }
  1925.             
  1926.             Boolean        IsEmpty()
  1927.                             { return fHead == NULL; }
  1928.                             
  1929.             void        AddFirst(OTLink* link)
  1930.                             { OTAddFirst(this, link); }
  1931.             
  1932.             void        AddLast(OTLink* link)
  1933.                             { OTAddLast(this, link); }
  1934.             
  1935.             OTLink*        GetFirst()
  1936.                             { return OTGetFirst(this); }
  1937.             
  1938.             OTLink*        GetLast()
  1939.                             { return OTGetLast(this); }
  1940.             
  1941.             OTLink*        RemoveFirst()
  1942.                             { return OTRemoveFirst(this); }
  1943.             
  1944.             OTLink*        RemoveLast()
  1945.                             { return OTRemoveLast(this); }
  1946.                             
  1947.             Boolean        IsInList(OTLink* link)
  1948.                             { return OTIsInList(this, link); }
  1949.                             
  1950.             OTLink*        FindLink(OTListSearchProcPtr proc, const void* ref)
  1951.                             { return OTFindLink(this, proc, ref); }
  1952.                             
  1953.             Boolean        RemoveLink(OTLink* link)
  1954.                             { return OTRemoveLink(this, link); }
  1955.                             
  1956.             OTLink*        RemoveLink(OTListSearchProcPtr proc, const void* ref)
  1957.                             { return OTFindAndRemoveLink(this, proc, ref); }
  1958.                             
  1959.             OTLink*        GetIndexedLink(size_t index)
  1960.                             { return OTGetIndexedLink(this, index); }
  1961. #endif
  1962. };
  1963.  
  1964. #define OTGetLinkObject(link, struc, field)    \
  1965.     ((struc*)((char*)(link) - offsetof(struc, field)))
  1966.  
  1967. /*    -------------------------------------------------------------------------
  1968.     ** Atomic Operations
  1969.     **
  1970.     ** The Bit operations return the previous value of the bit (0 or non-zero).
  1971.     ** The memory pointed to must be a single byte and only bits 0 through 7 are
  1972.     ** valid.  Bit 0 corresponds to a mask of 0x01, and Bit 7 to a mask of 0x80.
  1973.     ------------------------------------------------------------------------- */
  1974.  
  1975. typedef UInt8    OTLock;
  1976.  
  1977. #if GENERATING68K
  1978.  
  1979. #pragma parameter __D0 OTAtomicSetBit(__A0, __D0)
  1980. Boolean OTAtomicSetBit(UInt8*, size_t) =
  1981. {
  1982.     0x01d0, 0x56c0,    /* bset.b d0,(a0); sne d0 */
  1983.     0x7201, 0xc081    /* moveq #1,d1; and.l d1,d0 */
  1984. };
  1985.     
  1986. #pragma parameter __D0 OTAtomicClearBit(__A0, __D0)
  1987. Boolean OTAtomicClearBit(UInt8*, size_t) =
  1988. {
  1989.     0x0190, 0x56c0,    /* bclr.b d0,(a0); sne d0 */
  1990.     0x7201, 0xc081    /* moveq #1,d1; and.l d1,d0 */
  1991. };
  1992.     
  1993. #pragma parameter __D0 OTAtomicTestBit(__A0, __D0)
  1994. Boolean OTAtomicTestBit(UInt8*, size_t) =
  1995. {
  1996.     0x0110, 0x56c0,    /* btst.b d0,(a0); sne d0 */
  1997.     0x7201, 0xc081    /* moveq #1,d1; and.l d1,d0 */
  1998. };
  1999.  
  2000. #pragma parameter __D0 OTCompareAndSwapPtr(__D0, __D1, __A0)
  2001. Boolean OTCompareAndSwapPtr(void*, void*, void**) =
  2002. {
  2003.     0x0ed0, 0x0040,        /*    cas.l    d0,d1,(a0)    */
  2004.     0x57c0,                /*    seq        d0            */
  2005.     0x7201, 0xc081        /* moveq #1,d1; and.l d1,d0 */
  2006. };
  2007.  
  2008. #pragma parameter __D0 OTCompareAndSwap32(__D0, __D1, __A0)
  2009. Boolean OTCompareAndSwap32(UInt32, UInt32, UInt32*) =
  2010. {
  2011.     0x0ed0, 0x0040,        /*    cas.l    d0,d1,(a0)    */
  2012.     0x57c0,                /*    seq        d0            */
  2013.     0x7201, 0xc081        /* moveq #1,d1; and.l d1,d0 */
  2014. };
  2015.  
  2016. #pragma parameter __D0 OTCompareAndSwap16(__D0, __D1, __A0)
  2017. Boolean OTCompareAndSwap16(UInt32, UInt32, UInt16*) =
  2018. {
  2019.     0x0cd0, 0x0040,        /*    cas.w    d0,d1,(a0)    */
  2020.     0x57c0,                /*    seq        d0            */
  2021.     0x7201, 0xc081        /* moveq #1,d1; and.l d1,d0 */
  2022. };
  2023.  
  2024. #pragma parameter __D0 OTCompareAndSwap8(__D0, __D1, __A0)
  2025. Boolean OTCompareAndSwap8(UInt32, UInt32, UInt8*) =
  2026. {
  2027.     0x0ad0, 0x0040,        /*    cas.b    d0,d1,(a0)    */
  2028.     0x57c0,                /*    seq        d0            */
  2029.     0x7201, 0xc081        /* moveq #1,d1; and.l d1,d0 */
  2030. };
  2031.  
  2032. #pragma parameter __D0 OTAtomicAdd32(__D0, __A0)
  2033. SInt32 OTAtomicAdd32(SInt32, SInt32*) =
  2034. {
  2035.     0x2240,                /*         move.l    d0,a1        */
  2036.     0x2210,                /*@1    move.l    (a0),d1        */
  2037.     0x2001,                /*        move.l    d1,d0        */
  2038.     0xd089,                /*        add.l    a1,d0        */
  2039.     0x0ed0, 0x0001,        /*        cas.l    d1,d0,(a0)    */
  2040.     0x66f4                /*        bne.s    @1            */
  2041. };
  2042.         
  2043. #elif GENERATINGPOWERPC
  2044.  
  2045. extern Boolean OTAtomicSetBit(UInt8*, size_t);
  2046. extern Boolean OTAtomicClearBit(UInt8*, size_t);
  2047. extern Boolean OTAtomicTestBit(UInt8*, size_t);
  2048. //
  2049. // WARNING! void* and UInt32 locations MUST be on 4-byte boundaries.
  2050. //            UInt16 locations must not cross a 4-byte boundary.
  2051. //
  2052. extern Boolean    OTCompareAndSwapPtr(void* oldValue, void* newValue, void** location);
  2053. extern Boolean    OTCompareAndSwap32(UInt32 oldValue, UInt32 newValue, UInt32* location);
  2054. extern Boolean    OTCompareAndSwap16(UInt32 oldValue, UInt32 newValue, UInt16* location);
  2055. extern Boolean    OTCompareAndSwap8(UInt32 oldValue, UInt32 newValue, UInt8* location);
  2056. //
  2057. // WARNING! UInt32 locations MUST be on 4-byte boundaries.
  2058. //            UInt16 locations must not cross a 4-byte boundary.
  2059. //
  2060. extern SInt32    OTAtomicAdd32(SInt32, SInt32*);
  2061.  
  2062. #endif
  2063.  
  2064. extern SInt16    OTAtomicAdd16(SInt32, SInt16*);
  2065. extern SInt8    OTAtomicAdd8(SInt32, SInt8*);
  2066.  
  2067. #define OTClearLock(lockPtr)    *(lockPtr) = 0
  2068. #define OTAcquireLock(lockPtr)    (OTAtomicSetBit(lockPtr, 0) == 0)
  2069.  
  2070. #ifdef __cplusplus
  2071. }
  2072. #endif
  2073.  
  2074. /*******************************************************************************
  2075. **
  2076. ** FROM HERE ON DOWN ARE THE C++ Interfaces to Open Transport
  2077. **
  2078. ********************************************************************************/
  2079.  
  2080. #ifdef __cplusplus
  2081.  
  2082. /*    -------------------------------------------------------------------------
  2083.     CLASS TProvider
  2084.     
  2085.     This class provides the client interface to a Stream.  Typically, clients
  2086.     talk to an object (or glue code in front of the object) that is a subclass
  2087.     of TProvider.
  2088.     ------------------------------------------------------------------------- */
  2089.  
  2090. #if !OTKERNEL
  2091.  
  2092. class TProvider
  2093. {
  2094.     private:
  2095.         void*        operator new(size_t)    { return NULL; }
  2096.         void        operator delete(void*)    {}
  2097.         
  2098.     //
  2099.     // This is the public interface to a TProvider.  All other public
  2100.     // methods normally come from the subclass.
  2101.     //
  2102.     public:    
  2103.         OSStatus    Close()                { return OTCloseProvider(this); }
  2104.  
  2105.         OSStatus    SetNonBlocking()    { return OTSetNonBlocking(this); }
  2106.         OSStatus    SetBlocking()        { return OTSetBlocking(this); }
  2107.         Boolean        IsBlocking()        { return OTIsBlocking(this); }
  2108.         Boolean        IsNonBlocking()        { return !OTIsBlocking(this); }
  2109.         OSStatus    SetSynchronous()    { return OTSetSynchronous(this); }
  2110.         OSStatus    SetAsynchronous()    { return OTSetAsynchronous(this); }
  2111.         Boolean        IsSynchronous()        { return OTIsSynchronous(this); }
  2112.         Boolean        IsAsynchronous()    { return !OTIsSynchronous(this); }
  2113.         
  2114.         OSStatus    AckSends()            { return OTAckSends(this); }
  2115.         OSStatus    DontAckSends()        { return OTDontAckSends(this); }
  2116.         Boolean        IsAckingSends()        { return OTIsAckingSends(this); }
  2117.  
  2118.         void        CancelSynchronousCalls(OSStatus err)
  2119.                     { (void)OTCancelSynchronousCalls(this, err); }
  2120.  
  2121.         OSStatus    InstallNotifier(OTNotifyProcPtr proc, void* ptr)
  2122.                     { return OTInstallNotifier(this, proc, ptr); }
  2123.  
  2124.         OSStatus    UseSyncIdleEvents()
  2125.                     { return OTUseSyncIdleEvents(this, true); }
  2126.  
  2127.         OSStatus    DontUseSyncIdleEvents()
  2128.                     { return OTUseSyncIdleEvents(this, false); }
  2129.                     
  2130.         void        RemoveNotifier()
  2131.                     { OTRemoveNotifier(this); }
  2132.         
  2133.         Boolean        EnterNotifier()
  2134.                     { return OTEnterNotifier(this); }
  2135.                     
  2136.         void        LeaveNotifier()
  2137.                     { OTLeaveNotifier(this); }
  2138.                     
  2139.         OTPortRef    GetOTPortRef()
  2140.                     { return OTGetProviderPortRef(this); }
  2141.                     
  2142.         ProviderRef    TransferOwnership(OTClient prevOwner, OSStatus* errPtr)
  2143.                     { return OTTransferProviderOwnership(this, prevOwner, errPtr); }
  2144.                     
  2145.         SInt32        Ioctl(UInt32 cmd, void* data)
  2146.                     { return OTIoctl(this, cmd, data); }
  2147.         SInt32        Ioctl(UInt32 cmd, long data)
  2148.                     { return OTIoctl(this, cmd, (void*)data); }
  2149.                     
  2150.         OTResult    GetMessage(struct strbuf* ctlbuf, struct strbuf* databuf, OTFlags* flagPtr)
  2151.                     { return OTGetMessage(this, ctlbuf, databuf, flagPtr); }
  2152.         OTResult    GetPriorityMessage(struct strbuf* ctlbuf, struct strbuf* databuf,
  2153.                                        OTBand* bandPtr, OTFlags* flagPtr)
  2154.                     { return OTGetPriorityMessage(this, ctlbuf, databuf, bandPtr, flagPtr); }
  2155.         OSStatus    PutMessage(const struct strbuf* ctlbuf, const struct strbuf* databuf,
  2156.                                OTFlags flags)
  2157.                     { return OTPutMessage(this, ctlbuf, databuf, flags); }
  2158.         OSStatus    PutPriorityMessage(const struct strbuf* ctlbuf, const struct strbuf* databuf,
  2159.                                        OTBand band, OTFlags flags)
  2160.                     { return OTPutPriorityMessage(this, ctlbuf, databuf, band, flags); }
  2161.                     
  2162. };
  2163.         
  2164. /*    -------------------------------------------------------------------------
  2165.     Class TEndpoint
  2166.     
  2167.     This class is the interface to all TPI modules, which constitute the
  2168.     vast majority of protocols, with the exception of link-layer protocols.
  2169.     ------------------------------------------------------------------------- */
  2170.  
  2171. class TEndpoint : public TProvider
  2172. {
  2173.     public:
  2174.     //
  2175.     // Miscellaneous informative functions
  2176.     //
  2177.         OSStatus    GetEndpointInfo(TEndpointInfo* info)
  2178.                     { return OTGetEndpointInfo(this, info); }
  2179.                     
  2180.         OSStatus    GetProtAddress(TBind* boundAddr, TBind* peerAddr)
  2181.                     { return OTGetProtAddress(this, boundAddr, peerAddr); }
  2182.                     
  2183.         OSStatus    ResolveAddress(TBind* reqAddr, TBind* retAddr, OTTimeout timeout)
  2184.                     { return OTResolveAddress(this, reqAddr, retAddr, timeout); }
  2185.                     
  2186.         OTResult    GetEndpointState()        
  2187.                     { return OTGetEndpointState(this); }
  2188.                     
  2189.         OTResult    Look()
  2190.                     { return OTLook(this); }
  2191.                     
  2192.         OTResult    Sync()
  2193.                     { return OTSync(this); }
  2194.     //
  2195.     // Allocating structures
  2196.     //
  2197.         void*        Alloc(OTStructType structType, UInt32 fields, OSStatus* err = NULL)
  2198.                     { return OTAlloc(this, structType, fields, err); }
  2199.                     
  2200.         OTResult    Free(void* ptr, OTStructType structType)
  2201.                     { return OTFree(ptr, structType); }
  2202.     //
  2203.     // Option Management
  2204.     //
  2205.         OSStatus    OptionManagement(TOptMgmt* req, TOptMgmt* ret)
  2206.                     { return OTOptionManagement(this, req, ret); }
  2207.     //
  2208.     // Bind/Unbind
  2209.     //
  2210.         OSStatus    Bind(TBind* reqAddr, TBind* retAddr)
  2211.                     { return OTBind(this, reqAddr, retAddr); }
  2212.                     
  2213.         OSStatus    Unbind()
  2214.                     { return OTUnbind(this); }
  2215.     //
  2216.     // Connection creation and tear-down
  2217.     //
  2218.         OSStatus    Connect(TCall* sndCall, TCall* rcvCall)
  2219.                     { return OTConnect(this, sndCall, rcvCall); }
  2220.                     
  2221.         OSStatus    RcvConnect(TCall* call)
  2222.                     { return OTRcvConnect(this, call); }
  2223.                     
  2224.         OSStatus    Listen(TCall* call)
  2225.                     { return OTListen(this, call); }
  2226.                     
  2227.         OSStatus    Accept(EndpointRef resRef, TCall* call)
  2228.                     { return OTAccept(this, resRef, call); }
  2229.                     
  2230.         OSStatus    SndDisconnect(TCall* call)
  2231.                     { return OTSndDisconnect(this, call); }
  2232.                     
  2233.         OSStatus    SndOrderlyDisconnect()
  2234.                     { return OTSndOrderlyDisconnect(this); }
  2235.                     
  2236.         OSStatus    RcvDisconnect(TDiscon* discon)
  2237.                     { return OTRcvDisconnect(this, discon); }
  2238.                     
  2239.         OSStatus    RcvOrderlyDisconnect()
  2240.                     { return OTRcvOrderlyDisconnect(this); }
  2241.     //
  2242.     // Connection-oriented data transfer
  2243.     //
  2244.         OTResult    Snd(void* buf, size_t nbytes, OTFlags flags)
  2245.                     { return OTSnd(this, buf, nbytes, flags); }
  2246.                     
  2247.         OTResult    Rcv(void* buf, size_t nbytes, OTFlags* flagP)
  2248.                     { return OTRcv(this, buf, nbytes, flagP); }
  2249.     //
  2250.     // Non-connection-oriented data transfer
  2251.     //
  2252.         OSStatus    SndUData(TUnitData* udata)
  2253.                     { return OTSndUData(this, udata); }
  2254.                     
  2255.         OSStatus    RcvUData(TUnitData* udata, OTFlags* flagP)
  2256.                     { return OTRcvUData(this, udata, flagP); }
  2257.                     
  2258.         OSStatus    RcvUDErr(TUDErr* uderr)
  2259.                     { return OTRcvUDErr(this, uderr); }
  2260.     //
  2261.     // Connection-oriented transactions
  2262.     //
  2263.         OSStatus    SndRequest(TRequest* req, OTFlags reqFlags)
  2264.                     { return OTSndRequest(this, req, reqFlags); }
  2265.  
  2266.         OSStatus    RcvReply(TReply* reply, OTFlags* replyFlags)
  2267.                     { return OTRcvReply(this, reply, replyFlags); }
  2268.                     
  2269.         OSStatus    SndReply(TReply* reply, OTFlags flags)
  2270.                     { return OTSndReply(this, reply, flags); }
  2271.                     
  2272.         OSStatus    RcvRequest(TRequest* req, OTFlags* flags)
  2273.                     { return OTRcvRequest(this, req, flags); }
  2274.                     
  2275.         OSStatus    CancelRequest(OTSequence seq)
  2276.                     { return OTCancelRequest(this, seq); }
  2277.                     
  2278.         OSStatus    CancelReply(OTSequence seq)
  2279.                     { return OTCancelReply(this, seq); }
  2280.     //
  2281.     // Non-connection-oriented transactions
  2282.     //
  2283.         OSStatus    SndURequest(TUnitRequest* req, OTFlags reqFlags)
  2284.                     { return OTSndURequest(this, req, reqFlags); }
  2285.  
  2286.         OSStatus    RcvUReply(TUnitReply* reply, OTFlags* replyFlags)
  2287.                     { return OTRcvUReply(this, reply, replyFlags); }
  2288.                     
  2289.         OSStatus    SndUReply(TUnitReply* reply, OTFlags flags)
  2290.                     { return OTSndUReply(this, reply, flags); }
  2291.                     
  2292.         OSStatus    RcvURequest(TUnitRequest* req, OTFlags* flags)
  2293.                     { return OTRcvURequest(this, req, flags); }
  2294.                     
  2295.         OSStatus    CancelURequest(OTSequence seq)
  2296.                     { return OTCancelURequest(this, seq); }
  2297.                     
  2298.         OSStatus    CancelUReply(OTSequence seq)
  2299.                     { return OTCancelUReply(this, seq); }
  2300.     //
  2301.     // Miscellaneous functions
  2302.     //
  2303.         OTResult    CountDataBytes(size_t* countPtr)
  2304.                     { return OTCountDataBytes(this, countPtr); }
  2305. };
  2306.  
  2307. /*    -------------------------------------------------------------------------
  2308.     CLASS TMapper
  2309.     
  2310.     This class is the interface to naming protocols.
  2311.     ------------------------------------------------------------------------- */
  2312.  
  2313. class TMapper : public TProvider
  2314. {
  2315.     public:
  2316.         OSStatus    RegisterName(TRegisterRequest* req, TRegisterReply* reply)
  2317.                     { return OTRegisterName(this, req, reply); }
  2318.                 
  2319.         OSStatus    DeleteName(TNetbuf* name)
  2320.                     { return OTDeleteName(this, name); }
  2321.                 
  2322.         OSStatus    DeleteName(OTNameID id)    
  2323.                     { return OTDeleteNameByID(this, id); }
  2324.                 
  2325.         OSStatus    LookupName(TLookupRequest* req, TLookupReply* reply)
  2326.                     { return OTLookupName(this, req, reply); }
  2327. };
  2328.     
  2329. #endif    /* OTKERNEL    */
  2330. #endif    /* __cplusplus */
  2331.  
  2332. #if PRAGMA_ALIGN_SUPPORTED
  2333. #pragma options align=reset
  2334. #endif
  2335. #if PRAGMA_IMPORT_SUPPORTED
  2336. #pragma import off
  2337. #endif
  2338.  
  2339. #if GENERATING68K && defined(__MWERKS__)
  2340. #pragma pointers_in_A0
  2341. #endif
  2342.  
  2343. #endif    /* __OPENTRANSPORT__ */
  2344.  
  2345.